首页 > 其他 > 详细

CheckBox控件

时间:2015-01-31 00:05:18      阅读:318      评论:0      收藏:0      [点我收藏+]

 

前台代码:

1 <asp:CheckBox ID="CheckBox1" runat="server" Text ="苹果"/>
2 <asp:CheckBox ID="CheckBox2" runat="server" Text ="柠檬"/>
3 <asp:CheckBox ID="CheckBox3" runat="server" Text ="橘子"/>
4 <asp:CheckBox ID="CheckBox4" runat="server" Text ="桃子"/>
5 <asp:Button ID="Button2" runat="server" Text="结果" OnClick ="Button2_Click"/>
6 <asp:Label ID="Label2" runat="server" Text=""></asp:Label>

 

后台代码:

 1 /// <summary>
 2 /// Button单击事件
 3 /// </summary>
 4 /// <param name="sender"></param>
 5 /// <param name="e"></param>
 6 protected void Button2_Click(object sender, EventArgs e)
 7 {
 8     string s = string.Empty;
 9 
10     if (this.CheckBox1.Checked)
11     {
12         s += this.CheckBox1.Text + " ";
13     }
14     if (this.CheckBox2.Checked)
15     {
16         s += this.CheckBox2.Text + " ";
17     }
18     if (this.CheckBox3.Checked)
19     {
20         s += this.CheckBox3.Text + " ";
21     }
22     if (this.CheckBox4.Checked)
23     {
24         s += this.CheckBox4.Text + " ";
25     }
26 
27     this.Label2.Text = "你选择的水果有:" + s;
28 }

 

最终效果;

技术分享

 

以上就是CheckBox控件的用法。

 

CheckBox控件

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

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