首页 > 其他 > 详细

CheckBoxList控件

时间:2015-01-31 00:02:47      阅读:264      评论:0      收藏:0      [点我收藏+]

 

前台代码:

1 <asp:CheckBoxList ID="CheckBoxList1" runat="server">
2     <asp:ListItem Text ="苹果"></asp:ListItem>
3     <asp:ListItem Text ="柠檬"></asp:ListItem>
4     <asp:ListItem Text ="橘子"></asp:ListItem>
5     <asp:ListItem Text ="桃子"></asp:ListItem>
6 </asp:CheckBoxList>
7 <asp:Button ID="Button1" runat="server" Text="结果" OnClick ="Button1_Click"/>
8 <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

 

后台代码:

 1 /// <summary>
 2 /// Button单击事件
 3 /// </summary>
 4 /// <param name="sender"></param>
 5 /// <param name="e"></param>
 6 protected void Button1_Click(object sender, EventArgs e)
 7 {
 8     string s = string.Empty;
 9 
10     for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
11     {
12         if (this.CheckBoxList1.Items[i].Selected)
13         {
14             s += this.CheckBoxList1.Items[i].Text + " ";
15         }
16     }
17     this.Label1.Text = "你选择的水果有:" + s;
18 }

 

最终效果:

技术分享

 

以上就是CheckBoxList控件的简单用法。

 

CheckBoxList控件

原文:http://www.cnblogs.com/KTblog/p/4263387.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!