how to set the default value to the drop down list control?

后端 未结 4 1249
名媛妹妹
名媛妹妹 2020-12-17 17:59

I have a drop down list control on my web page. I have bind the datatable to the dropdownlist control as follows -

lstDepartment.DataTextField = \"Department         


        
4条回答
  •  不思量自难忘°
    2020-12-17 18:34

    Assuming that the DropDownList control in the other table also contains DepartmentName and DepartmentID:

    lstDepartment.ClearSelection();
    
    foreach (var item in lstDepartment.Items) 
    {
      if (item.Value == otherDropDownList.SelectedValue)
      {
        item.Selected = true;
      }
    }

提交回复
热议问题