CheckBoxList1复选框
2014-03-28 14:00
260 查看
循环绑定数据的两个方法:
List<string> LIColl = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
foreach (SPUser user in web.AllUsers)//遍历所有用户
{
CheckBoxList1.Items.Add(user.Name);//直接绑定
LIColl.Add(user.Name);
//approversCollection.Add(new SPFieldUserValue(web,user.ID,user.LoginName));
}
//CheckBoxList1.DataSource = LIColl;//后续绑定
//CheckBoxList1.DataBind();//后续绑定
读取
private static string selval;//读取后放到里面去
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
selval += CheckBoxList1.Items[i].Text + ";" + selval;
}
}
}
判断是否选中:
后台:
前台js
List<string> LIColl = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
foreach (SPUser user in web.AllUsers)//遍历所有用户
{
CheckBoxList1.Items.Add(user.Name);//直接绑定
LIColl.Add(user.Name);
//approversCollection.Add(new SPFieldUserValue(web,user.ID,user.LoginName));
}
//CheckBoxList1.DataSource = LIColl;//后续绑定
//CheckBoxList1.DataBind();//后续绑定
读取
private static string selval;//读取后放到里面去
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
selval += CheckBoxList1.Items[i].Text + ";" + selval;
}
}
}
判断是否选中:
后台:
int count = 0; foreach (ListItem item in this.CheckBoxList1.Items) { if (item.Selected) { count++; } } if (count == 0) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), string.Format("<script>alert('请选择人员!')</script>")); return; } else { }
前台js
<script type="text/javascript"> function Copy() { var dutyflag = 0; //ctl00_ctl33_g_5faa55c8_cfe2_4734_9517_ee7dfc9e832d_ctl00_CheckBoxList1_0 var checkobj = document.getElementById("ctl00_ctl33_g_5faa55c8_cfe2_4734_9517_ee7dfc9e832d_ctl00_CheckBoxList1"); var checks = checkobj.getElementsByTagName("input"); for (var n = 0; n < checks.length; n++) { if (checks .type == "checkbox" && checks .checked == true) { dutyflag = 1; } } if (dutyflag == 0) { alert("至少要选择1个部门"); return false; } else { var value = document.getElementById("<%=divnr.ClientID %>").innerHTML; var real = value.replace(/<[^>]*>/g, "").replace(/ /g, "").replace(/\s+/g, ""); if (real == "") { //alert("real is null"); document.getElementById("<%=HiddenFieldnr.ClientID %>").value = ""; } else { //alert("real is not null: "+real) document.getElementById("<%=HiddenFieldnr.ClientID %>").value = value; } var valu = document.getElementById("<%=divnb.ClientID %>").innerHTML; var rea = valu.replace(/<[^>]*>/g, "").replace(/ /g, "").replace(/\s+/g, ""); if (rea == "") { //alert("real is null"); document.getElementById("<%=HiddenFieldnb.ClientID %>").value = ""; } else { //alert("real is not null: "+real) document.getElementById("<%=HiddenFieldnb.ClientID %>").value = valu; } return true; } } </script> <asp:Button ID="Button1" runat="server" Text="发送" OnClientClick="return Copy()" OnClick="Button1_Click" />
相关文章推荐
- CHECKBOXLIST脚本控制复选框选择个数
- ASP.NET CheckBoxList复选框
- 获取ListControl控件中(复选框)CheckBox的状态
- ASP.NET中CheckBoxList复选框列表控件详细使用方法
- Devexpress TreeList CheckBox 复选框
- CheckBoxList复选框组
- asp.net CheckBoxList 取值与勾选,复选框后台控制前台checkbox选中
- ASP.net(c#)取得CheckBoxList(复选框)的值
- 获取ListControl控件中(复选框)CheckBox的状态
- asp.net CheckBoxList 取值与勾选,复选框后台控制前台checkbox选中
- asp.net CheckBoxList 取值与勾选,复选框后台控制前台checkbox选中
- asp.net CheckBoxList 取值与勾选,复选框后台控制前台checkbox选中
- 20151224:Web:CheckBoxList 控件:去重显示 ;复选框多选时可点击查询查出结果
- checkboxlist 下拉框多选功能 ,模拟dropdownlist带复选框效果
- ASP.NET中CheckBoxList复选框列表控件详细使用方法
- 关于复选框input[type=checkbox]
- CheckBox为CheckBoxList实现全选或全取消选择(js代码实现)
- COCOS学习笔记--复选框CheckBox及其控件属性
- WIN SDK 添加Tab控件 List Control with CheckBox
- gridview和checkboxlist的嵌套相关应用