DropDownList1的值不能重复
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
if (!Page.IsPostBack)
{
ListItem l1 = new ListItem();
l1.Value = "1";
l1.Text = "flow1";
DropDownList1.Items.Add(l1);
ListItem l2 = new ListItem();
l2.Value = "1";
l2.Text = "flow2";
DropDownList1.Items.Add(l2);
ListItem l3 = new ListItem();
l3.Value = "1";
l3.Text = "flow3";
DropDownList1.Items.Add(l3);
ListItem l4 = new ListItem();
l4.Value = "1";
l4.Text = "flow4";
DropDownList1.Items.Add(l4);
ListItem l5 = new ListItem();
l5.Value = "1";
l5.Text = "flow5";
DropDownList1.Items.Add(l5);
ListItem l6 = new ListItem();
l6.Value = "1";
l6.Text = "flow6";
DropDownList1.Items.Add(l6);
ListItem l7 = new ListItem();
l7.Value = "8";
l7.Text = "flow7";
DropDownList1.Items.Add(l7);
ListItem l8 = new ListItem();
l8.Value = "11";
l8.Text = "flow8";
DropDownList1.Items.Add(l8);
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedItem.Text;
}
当 DropDownList1选择的值是 flow1 到 flow6 时,显示的值为空,真不知为什么
只有选择 flow7 flow8 Label1.Text 的值才会显示