Hi , i hv created 2 tables : a Department table with fields Deptname , Deptid and Employee table with Empid , Empname, Salary .
I have created a datagrid with fields empname , address , Salary , Deptname and edit and delete command columns . By clicking on edit , it redirects to another form with 3 textboxes ( name , address , salary) and a dropdownlist with department names and update button .So data will get edited and updated after clicking on update button .
I have binded the dropdownlist with values from database . I have used a query string using which data from datagrid is populated into the textboxes on the second page .
The problem that I am facing is that the deptnames for each row in datagrid r not getting selected in the dropdownlist while trying to edit.
The code used for binding the dropdownlist with database is as follows :
protected void FillDeptDropDownList()
{
String strConnString = ConfigurationManager.ConnectionStrings["Company"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("Select * from Department", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "DeptName";
DropDownList1.DataValueField = "DeptID";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "Select department name:");
}
Please help with dis issue .