.net学习笔记6--ListBox

mac2022-06-30  30

ListBox与DropListBox的功能几乎一样,不同的是ListBox控件是一次性将所有的选项显示出来。

<div> <asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"> <asp:ListItem>语文</asp:ListItem> <asp:ListItem>数学</asp:ListItem> <asp:ListItem>英语</asp:ListItem> <asp:ListItem>体育</asp:ListItem> </asp:ListBox> <asp:Button ID="Button1" runat="server" Text="-->" onclick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="<--" onclick="Button2_Click" /> <asp:ListBox ID="ListBox2" runat="server" SelectionMode="Multiple"></asp:ListBox> </div> protected void Button1_Click(object sender, EventArgs e) { move(ListBox1, ListBox2); } protected void Button2_Click(object sender, EventArgs e) { move(ListBox2, ListBox1); } void move(ListBox srcList, ListBox destList) { for (int i = srcList.Items.Count - 1; i >= 0; i--) { ListItem item = srcList.Items[i]; if (item.Selected) { destList.Items.Add(item); srcList.Items.Remove(item); } } }
最新回复(0)