PS:最近在做权限管理这个模块,发现用checkbox的地方挺多的,于是写了个简单的例子,以供以后学习和使用。
1.前端页面:
张三
李四
王五
赵六
孙琦
猪八
2.后台方法:
#region 获取从前端页面回传过来的 CheckBox 的值 void GetCheckBoxValue()
///
/// 获取从前端页面回传过来的 CheckBox 的值
/// Request.Form["chk_per"] 以逗号分割,获取所有选中的 CheckBox 的值
///
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();
}
}
本文介绍了一个关于权限管理模块中使用Checkbox的例子。前端显示了多个用户选项,如张三、李四等,后端通过`GetCheckBoxValue`方法获取前端选中的用户,利用Request.Form和逗号分割获取Checkbox的值。该方法适用于处理多选提交场景。
251

被折叠的 条评论
为什么被折叠?



