C# 选择DropDownList1值时,在DropDownList2中存储重复值

C# 选择DropDownList1值时,在DropDownList2中存储重复值,c#,asp.net,C#,Asp.net,DropDownList1不显示重复值,但当我选择dropdownlist2时,它显示重复值。如果(!IsPostBack)简单地说,我不明白哪个代码加载项 if(!IsPostBack) { DropDownList1.Items.Insert(0, new ListItem("Select Category")); SqlDataReader dr = DAL.ExecuteReaderDemo("select * from addcategory"); whi

DropDownList1不显示重复值,但当我选择dropdownlist2时,它显示重复值。如果(!IsPostBack)

简单地说,我不明白哪个代码加载项

if(!IsPostBack)
   {
     DropDownList1.Items.Insert(0, new ListItem("Select Category"));
     SqlDataReader dr = DAL.ExecuteReaderDemo("select * from addcategory");
  while (dr.HasRows)
      {
        dr.Read();
 DropDownList1.Items.Insert(1, new ListItem(dr[1].ToString(), dr[0].ToString()));
       }
         dr.Close();
            }
        }

使用DropDownList1.Items.Clear()将其与其他下拉列表中的回发事件绑定之前。

是否设置了调试点,并尝试第二次查找代码命中率,
!IsPostBak
不允许回击,但您可以通过将断点放在此处来尝试DropDownList2绑定的代码在哪里?添加了答案,您是否可以尝试,并让我知道是否有任何问题使用DropDownList1.Items.Clear(),然后再将其与其他下拉列表中的回发事件绑定。在那里?你应该回复评论以获得更好的回答,我试试这个。但是我有两个DropDownList,我在DropDownList2中得到了重复的值。我的问题是通过DropDownList2.Items.Clear()解决的。好的,当您绑定dropdown1和dropdown2时,请清除前面的值
    if(!IsPostBack)
   {
     DropDownList1.Items.Clear()
     DropDownList1.Items.Insert(0, new ListItem("Select Category"));
     SqlDataReader dr = DAL.ExecuteReaderDemo("select * from addcategory");
  while (dr.HasRows)
      {
        dr.Read();
 DropDownList1.Items.Insert(1, new ListItem(dr[1].ToString(),dr[0].ToString()));
       }
         dr.Close();
 }