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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-19 我要评论
想了解WebForm获取checkbox选中的值(几个简单的示例)的相关内容吗,在本文为您仔细讲解WebForm checkbox的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:WebForm,checkbox,下面大家一起来学习吧。

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(); 
}
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们