<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<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("请选择分类", ""));
这个加不进去了。
<ContentTemplate>
<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("请选择分类", ""));
这个加不进去了。
这个放在DropDownList1.DataBind();上面呢
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();
先清空(放在前面)
DropDownList1.Items.Clear();