先看页面代码

 <asp:DataList id="DataList1" runat="server" Width="100%" RepeatColumns="4" Font-Size="10pt">
<ItemTemplate>
<TABLE id="Table2" cellSpacing="0" cellPadding="0" width="100%" bgColor="gainsboro" border="0">
<TR>
<TD align="center">
<asp:Label id=lblOName runat="server" Font-Size="10pt" Text='<%# DataBinder.eval_r(Container.DataItem,"nmenu_name")%>'>
</asp:Label>
<asp:Label id=lblID runat="server" Font-Size="10pt" Text='<%# DataBinder.eval_r(Container.DataItem,"nmenu_id")%>' Visible="False">
</asp:Label></TD>
</TR>
<TR>
<TD align="center">
<asp:CheckBoxList id="cbSelect" runat="server" Font-Size="10pt" RepeatColumns="2" Width="100%" BackColor="#FFE0C0"
RepeatDirection="Horizontal" DataTextField="nmenu_tname" DataValueField="nmenu_tid"></asp:CheckBoxList></TD>
</TR>
</TABLE>
</ItemTemplate>
</asp:DataList>

后台绑定CheckBox:

 private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
if(Session["UID"]!=null&&Session["UID"].ToString()!="")
{
BindList();
BindCheckBox();
}
else
{
Server.Transfer("error.aspx");
}
}
}
private void BindList()
{
string sql = "select * from NewsOne";
DataList1.DataSource = ort.ExecuteToTable(sql);
DataList1.DataBind();
}
private void BindCheckBox()
{
foreach(DataListItem dli in DataList1.Items)
{
CheckBoxList cbl = (CheckBoxList)dli.FindControl("cbSelect");
Label lbl = (Label)dli.FindControl("lblID");
string sql = "select * from NewsTwo where nmenu_oid="+lbl.Text;
cbl.DataSource = ort.ExecuteToTable(sql);
cbl.DataBind();
}
}

CheckBox取值:

 string list = "";
foreach(DataListItem dli in DataList1.Items)
{
CheckBoxList cbSel = (CheckBoxList)dli.FindControl("cbSelect");
for(int i=;i<cbSel.Items.Count;i++)
{
if(cbSel.Items[i].Selected == true)
{
list += cbSel.Items[i].Value + ",";
}
}
}
list = list.Trim(",".ToCharArray());

有的时候会出现取不到值的情况,我的看法是缺少if(!IsPostBack)。

DataList、Repeater、GridView中的Checkbox取值问题的更多相关文章

  1. 转:GridView中RowDataBound的取值

    GridView是ASP.NET中功能强大的数据显示控件,它的RowDataBound事件为我们提供了方便的控制行.列数据的途径. 要获取当前行的某个数据列,我在实践中总结有如下几种方法: 1. Ce ...

  2. aspx中的checkbox 取值问题

    问题:前台checkbox控件,选中值为1,不选值为0: 解决方案: 插入一行 <input type="hidden" name="RemberPwd" ...

  3. jQuery radio取值,checkbox取值,select取值

    语法解释: $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 var checkTex ...

  4. jquery ajax post 传递数组 ,多checkbox 取值

    jquery ajax post 传递数组 ,多checkbox 取值 http://w8700569.iteye.com/blog/1954396 使用$.each(function(){});可以 ...

  5. jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

    jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...

  6. easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

    获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $(" ...

  7. jquery radio取值,checkbox取值,select取值及选中

    jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关 获取一组radio被选中项的值 var item = $('in ...

  8. GridView中实现CheckBox的全选

    GridView中实现CheckBox的全选 用服务器端的方法: 在页面上放一个gridview控件,配置好数据源,编辑列, <asp:GridView ID="GridView1&q ...

  9. C#中float的取值范围和精度

    原文:C#中float的取值范围和精度 float类型的表现形式: 默认情况下,赋值运算符右侧的实数被视为 double. 因此,应使用后缀 f 或 F 初始化浮点型变量,如以下示例中所示: floa ...

随机推荐

  1. ASP.NET中在线用户统计

    统计在线用户的作用不言而喻,就是为了网站管理者可以知道当前用户的多少,然后根据用户数量来观察服务器或者程序的性能,从而可以直观的了解到网站的吸引力或者网站程序的效率.现在,我们就介绍一个简单明了的方法 ...

  2. Oracle语句块PL/SQL循环判断

    - --pl/sql Procedural Language /sql --被数据库编译保存,由用户调用 --程序块 /* 语法 Declare – 声明变量 --声明变量 Age int; //没有 ...

  3. 用pod导入ReactiveCocoa

    用pod导入ReactiveCocoa [1]   第一种 platform:ios,'7.0' pod 'ReactiveCocoa' [2]  第二种 pod 'ReactiveCocoa','2 ...

  4. 关于Repeater中绑定的控件不触发ItemCommand事件

    今天遇到 在repeater 中使用一个button,点击button然后跳转另外一个页面. html. <asp:Repeater ID="repeater" runat= ...

  5. web.config 拆分

    <appSettings configSource="xxx.config"> </appSettings> 在 web.config 加入上面  然后创建 ...

  6. [0] Tornado Todo 开篇

    参考自: python: tornado例子 Github地址:tornado_todo 开发环境: Python包的安装: 首先安装 pip: sudo apt-get install python ...

  7. python学习视频整理

    python3英文视频教程(全87集) http://pan.baidu.com/s/1dDnGBvV python从入门到精通视频(全60集)链接:http://pan.baidu.com/s/1e ...

  8. NET站点Web部署

    NET站点Web部署(一键发布的实现) 在开发过程中经常需要发布到开发环境.测试环境或者预发布环境上给其他同事进行测试验证效果等等,每次发布都要备份,拷贝,修改配置文件等等重复操作非常的麻烦,效率大打 ...

  9. sublime 插件 和free 注册码

    代码对齐: Alignment html代码补全:  Emmet CoffeeScript语法:  Better CoffeeScript css格式化:  CSS Format less语法:  L ...

  10. 【转】sqlmap用户手册

    http://192.168.136.131/sqlmap/mysql/get_int.php?id=1 当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数2.判断可以用那种SQL注入 ...