如何清除ASP.net DropDownList显示以前选择的项目

时间:2014-06-21 07:24:35

标签: asp.net

请帮助我如何恢复它。我使用了ddlHassection.Items.Clear();但它不能正常工作。

using (var context = new SMAPPDBEntities())
{
     var addDept = new SMDepartment
     {
          DepartmentCode = txtDeptCode.Text,
          DepartmentName = txtDeptName.Text,
          UnitID= Convert.ToInt32( ddlUnitName.SelectedValue),
          Description = txtDeptDescription.Text,
          DepartmentHead = Convert.ToInt32(ddlDeptHeadName.SelectedValue),
          HasSection = Convert.ToBoolean(ddlHasSection.SelectedValue),
          Tag= txtDeptTag.Text
      };
      try
      {
           context.SMDepartment.Add(addDept);
           context.SaveChanges();
       }
       catch (Exception ex)
       {
           ex.ToString();
       }
}

enter image description here enter image description here

1 个答案:

答案 0 :(得分:1)

protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
  DropDownList1.Items.Clear();
}

or

DDL1.ClearSelection();