网络编程 
首页 > 网络编程 > 浏览文章

WebForm获取checkbox选中的值(几个简单的示例)

(编辑:jimmy 日期: 2025/12/28 浏览:3 次 )

PS:最近在做权限管理这个模块,发现用checkbox的地方挺多的,于是写了个简单的例子,以供以后学习和使用。

1.前端页面:

<form id="form1" method="get" runat="server"> 
<input name="chk_per" type="checkbox" value="3" />张三 
<input name="chk_per" type="checkbox" value="4" />李四 
<input name="chk_per" type="checkbox" value="5" />王五 
<input name="chk_per" type="checkbox" value="6" />赵六 
<input name="chk_per" type="checkbox" value="7" />孙琦 
<input name="chk_per" type="checkbox" value="8" />猪八 
<input type="submit" id="btnOK" value="提交" /> 
</form>

2.后台方法:

#region 获取从前端页面回传过来的 CheckBox 的值 void GetCheckBoxValue() 
/// <summary> 
/// 获取从前端页面回传过来的 CheckBox 的值 
/// <para>Request.Form["chk_per"] 以逗号分割,获取所有选中的 CheckBox 的值</para> 
/// </summary> 
private void GetCheckBoxValue() 
{ 
string user = Request["chk_per"]; 
string[] users = user.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); 
string s = string.Empty; 
foreach (var item in users) 
{ 
s += item + " | "; 
} 
} 

#endregion
protected void Page_Load(object sender, EventArgs e) 
{ 
if (IsPostBack) 
{ 
//测试调用 
GetCheckBoxValue(); 
}
}
上一篇:在ASP.NET中支持断点续传下载大文件(ZT)源码
下一篇:.NET中获取程序根目录的常用方法介绍
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap