I have a problem while updating changing the item in dropdownlist.
I have a dropdownlist which is populated in code behind file.
Here is the code:
departmentComm = new SqlCommand("SELECT DepartmentID, Department FROM Departments", conn);
conn.Open();
reader = d开发者_运维技巧epartmentComm.ExecuteReader();
// Populate the list of categories
departmentList.DataSource = reader;
departmentList.DataValueField = "DepartmentID";
departmentList.DataTextField = "Department";
departmentList.DataBind();
// Close the reader
reader.Close();
I select one value from this list and saves it in my employee table. Now let's suppose I want to update this value in employee table.
Now my question is, how can I pull this value in dropdownlist and show it?
If you just van to get the selected department id:
departmentList.SelectedValue
gives you the id
If you embedded the dropdown in a datagrid you will need to update the database using a DataAdapter and call its Update method.
If you need more specifics you need to give more details.
精彩评论