Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdownlist that gets populated on pageload event.
now i want that as soon as i select that persons name in dropdown its all information and person working under him should populate in datagridview1 and datagridview2 respectively
please suggest i ma new to this tecnology


Here is the code:



public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string CS = ConfigurationManager.ConnectionStrings["hodconstr"].ConnectionString;
using (SqlConnection con = new SqlConnection("hodconstr"))
using (SqlCommand cmd = new SqlCommand("Select * from EMPLOYEE where DESIGNATIO = 'hod' AND ACTIVE = 'N'"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
sda.Fill(ds);
DDL1.DataSource = ds.Tables[0];
DDL1.DataTextField = "Name";
DDL1.DataValueField = "CustomerId";
DDL1.DataBind();
}
}
} DDL1.Items.Insert(0, new ListItem("--Select Inactive HOD'S--", "0"));
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

string CS = ConfigurationManager.ConnectionStrings["hodconstr"].ConnectionString;
using (SqlConnection con = new SqlConnection("hodconstr"))
using (SqlCommand cmd = new SqlCommand("Select EMP_NAME, EMP_CODE, EMP_DEPT, DEPARTMENT, DESIGNATIO from EMPLOYEE WHERE "))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
sda.Fill(ds);
GV1.DataSource = ds.Tables[0];
GV1.DataBind();
}


}
}
}
}
Posted
Comments
DamithSL 23-Sep-15 4:09am    
what you want in your where condition?

1 solution

all info of selected person in dropdownlist should appear in gridview1 and people working under him in gridview2

i was nopt able to figureout where statement because it depends on selection of dropdownlist

---------------------------------------------------------------------------------------

#1
Select upper(login) HODLogin,
Upper(Emp_Name) EmpName,
Designatio designation,
Upper(department) dept,
Division from employee
where login in
(select distinct hod from car_approver
where HOD in (Select login from employee where active = 'N' and emp_name not in (Select emp_name from employee where active ='Y'))
and hod <>'' ) Order by 2

<drop down=""> Inactive HODS

Inactive HOD Details

HOD Login HOD Name HOD Designation HOD Department HOD Division
PRASADS PRASAD SANYAL Editor - News, NDTV Convergence CONTENT : ENGLISH NEWS Content : English News

PRASADS – Vehicle approver of following employees –

Emp Code Emp Name
OG3138 Ajit Chandrakant Potle
OL2480 Antriksha Kumar Bhaskar
OP019 Dilip Kumar
OG1728 Gangamurali G Amballa
PA413 Indranil Sen
PA233 Jayant John
PA1592 Rajani
PA3702 Raman Kumar
TC6119 Ruchika Sawhney
OG194 Sanjeev Kumar
OG6497 SHEIKH JANESHAR AKHTER
OGO55 Subhash Chander
OG060 Sushil Kumar
OG6092 Vikas Gour
OG2173 Vinish Kumar
OD048 Zakir Hussain

#2
Select Emp_code, EmpName = (select emp_name from employee where emp_code = x.emp_code) from car_approver x where hod = 'PRASADS'
Order by 2

Select Emp_code, EmpName = (select emp_name from employee where emp_code = x.emp_code) from car_approver x where hod = 'VANDANAP'
Order by 2


Credentials:
Server : DEL-INTRASQL
Database Name: test
User/password: testu/test

• 1st query can give you multiple records
• 2nd query = login attribute should take values returned by 1st query
• Drop down for first query
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900