天天看點

dropDownList控件

asp.net2.0:dropDownList控件

外觀Body内:

<form id="form1" runat="server">     <div>         <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">         </asp:DropDownList>         <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="填充DropDownList" />         &nbsp;         <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="選擇一項" />         <asp:Label ID="Label1" runat="server"></asp:Label><br />         <br />         AutoPostBack設定為true後,觸發OnSelectedIndexChanged的事件立刻發送到伺服器</div>     </form>

内部事件: protected void Button1_Click(object sender, EventArgs e)     {         DropDownList1.Items.Add(new ListItem("name","spell"));         DropDownList1.Items.Add(new ListItem("age", "24"));         DropDownList1.Items.Add(new ListItem("sex", "boy"));     }     protected void Button2_Click(object sender, EventArgs e)     {         Label1.Text =DropDownList1.SelectedItem.Text+" : " +DropDownList1.SelectedItem.Value;     }     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)     {         Label1.Text = DropDownList1.SelectedItem.Text + " : " + DropDownList1.SelectedItem.Value;     }