<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    &nbsp;<asp:DropDownList ID="DropDownList2" runat="server">
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DropDownList2"
                        ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
                </ContentTemplate>
                <Triggers>
                    <atlas:ControlEventTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
                </Triggers>
            </atlas:UpdatePanel>------cs 代码 -----------------------------DropDownList1.DataSource = ds.Tables["lbname"];
            DropDownList1.DataValueField = "lbid";
            DropDownList1.DataTextField = "lbname";
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, new ListItem("请选择分类", ""));
            DropDownList1.AppendDataBoundItems = true;这样会有重复的数据,怎么解决?比如数据库是有记录为
1  abc
2  aaa
但是绑定到下拉框的时候变成了.
1  abc
2  aaa
1  abc
2  aaa
 DropDownList1.AppendDataBoundItems = true;
这个去了就不会有多重复的。

  DropDownList1.Items.Insert(0, new ListItem("请选择分类", ""));
这个加不进去了。

解决方案 »

  1.   

    DropDownList1.Items.Insert(0, new ListItem("请选择分类", ""));
    这个放在DropDownList1.DataBind();上面呢
      

  2.   

    可以先加到datatable 里面,然后绑定
      

  3.   

    weizhuangzhi(壮志) 的放上面不行。
      

  4.   

    DropDownList1.DataSource = ds.Tables["lbname"];
                DropDownList1.DataValueField = "lbid";
                DropDownList1.DataTextField = "lbname";
                DropDownList1.DataBind();
                DropDownList1.Items.Insert(0, new ListItem("请选择分类", ""));
                DropDownList1.AppendDataBoundItems = true;改为下面的看可以不:DropDownList1.AppendDataBoundItems = true;
    DropDownList1.Items.Insert(0, new ListItem("请选择分类", ""));
    DropDownList1.DataSource = ds.Tables["lbname"];
    DropDownList1.DataValueField = "lbid";
    DropDownList1.DataTextField = "lbname";
    DropDownList1.DataBind();
                
      

  5.   

    this.DropDownList1.Items.Clear();
    先清空(放在前面)
      

  6.   

    对了 设置了 AppendDataBoundItems  为true 后,最好在帮定数据前清空DropDownList1
      

  7.   

    在DropDownList1.DataSource = ds.Tables["lbname"];前面加上
    DropDownList1.Items.Clear();