开发者

problem updating dropdownlist

开发者 https://www.devze.com 2023-03-07 23:39 出处:网络
I have a problem while updating changing the item in dropdownlist. I have a dropdownlist which is populated in code behind file.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消