确定多重选择列表控件 (List Control) 中的选定内容
生活随笔
收集整理的这篇文章主要介绍了
确定多重选择列表控件 (List Control) 中的选定内容
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
确定多重选择列表控件 (List Control) 中的选定内容
依次通过控件的 Items 集合,分别测试每一项的 Selected 属性。
下面的示例显示如何测试多重选择 ListBox 控件(名为 ListBox1)的选定内容。代码将在一个标签中显示选定项的列表。
2Public Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
3 Dim msg As String
4 Dim li As ListItem
5 msg = ""
6 For Each li In ListBox1.Items
7 If li.Selected = True Then
8 msg = msg & "<BR>" & li.Text & " selected."
9 End If
10 Next
11 Label1.Text = msg
12End Sub
1// C#
2public void Button1_Click(object sender, System.EventArgs e)
3{
4 // Text that will display selected items
5 string msg = "" ;
6 foreach(ListItem li in ListBox1.Items)
7 {
8 if(li.Selected == true)
9 {
10 msg += "<BR>" + li.Text + " is selected.";
11 }
12 }
13 Label1.Text = msg;
14}
转载于:https://www.cnblogs.com/trendline/archive/2005/07/28/201706.html
总结
以上是生活随笔为你收集整理的确定多重选择列表控件 (List Control) 中的选定内容的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: “百度”(baidu.com)的由来
- 下一篇: 忍不住也谈招聘应聘程序员的事