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;     }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章