六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 12|回复: 0

asp.net CheckBoxList 取值与勾选,复选框后台控制前台checkbox选中

[复制链接]

升级  61.3%

726

主题

726

主题

726

主题

探花

Rank: 6Rank: 6

积分
2226
 楼主| 发表于 2013-2-4 20:11:42 | 显示全部楼层 |阅读模式
前台:
<asp:CheckBoxList ID = "cblJL" runat = "server" RepeatDirection="Horizontal" Width="100%">    <asp:ListItem>当前记录</asp:ListItem>    <asp:ListItem>当前页</asp:ListItem>    <asp:ListItem>全部记录</asp:ListItem></asp:CheckBoxList>

后台3种方式:
第一种:获得CheckBox的值

string save_cblJL = "";for (int i = 0; i < this.cblJL.Items.Count; i++){if (this.cblJL.Items[i].Selected == true){save_cblJL += this.cblJL.Items[i].Value + ",";}}Response.Write(save_cblJL);

第二种:获得CheckBox的值

string str_Save_cblJL = "";foreach (ListItem li in cblJL.Items){if (li.Selected == true){str_Save_cblJL += li.Value + ",";}}Response.Write(str_Save_cblJL);

第三种:从后台给前台CheckBox赋值

string strapp = "当前记录,当前页,全部记录,";string[] strtemp = strapp.Split(',');foreach (string str in strtemp){for (int i = 0; i < cblJL.Items.Count; i++){if (this.cblJL.Items[i].Value == str){this.cblJL.Items[i].Selected = true;}}}

黑色头发:http://heisetoufa.iteye.com/
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表