ListBox简单应用
ListBox-->SelectionMode屬性:列表的選擇模式
在工具箱拖放一個ListBox:
打開源:
<body>
??? <form id="form1" runat="server">
??? <div>
??????? <asp:TextBox ID="txtAddListValue" runat="server"></asp:TextBox>
??????? <asp:Button ID="btnSubmit" runat="server" Text="新增" οnclick="btnSubmit_Click" />
??????? <br /><br />
??????? <asp:ListBox ID="listValue" runat="server" SelectionMode="Multiple">
??????????? <asp:ListItem>張三</asp:ListItem>
??????????? <asp:ListItem>李四</asp:ListItem>
??????????? <asp:ListItem>王五</asp:ListItem>
??????????? <asp:ListItem>趙六</asp:ListItem>
??????? </asp:ListBox>
??????? <br /><br />
??????? <asp:Button ID="btnSure" runat="server" Text="選擇" οnclick="btnSure_Click" />
??????? <br />
??????? <asp:Label ID="labShow" runat="server"></asp:Label>
??? </div>
??? </form>
</body>
雙擊新增按鈕:
?? /// <summary>
??? /// 為ListBox新加一項值
??? /// </summary>
??? /// <param name="sender"></param>
??? /// <param name="e"></param>
??? protected void btnSubmit_Click(object sender, EventArgs e)
??? {
??????? listValue.Items.Add(txtAddListValue.Text.ToString());
??? }
雙擊選擇按鈕:
??? /// <summary>
??? /// 顯示選擇的值
??? /// </summary>
??? /// <param name="sender"></param>
??? /// <param name="e"></param>
??? protected void btnSure_Click(object sender, EventArgs e)
??? {
??????? labShow.Text = "您選擇的是:<br />";
??????? //遍歷控件
??????? foreach(ListItem li in listValue.Items)
??????? {
??????????? //獲取值
??????????? if(li.Selected)
??????????? {
??????????????? labShow.Text += li.Text + "<br>";
??????????? }
??????? }
??? }
轉載于:https://www.cnblogs.com/scsuns520/archive/2009/12/27/1633270.html
總結
以上是生活随笔為你收集整理的ListBox简单应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Javascript--Boolean运
- 下一篇: 在Access和 SQL Server中