DataList、Repeater、GridView中的Checkbox取值问题
先看页面代码
- <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取值问题的更多相关文章
- 转:GridView中RowDataBound的取值
GridView是ASP.NET中功能强大的数据显示控件,它的RowDataBound事件为我们提供了方便的控制行.列数据的途径. 要获取当前行的某个数据列,我在实践中总结有如下几种方法: 1. Ce ...
- aspx中的checkbox 取值问题
问题:前台checkbox控件,选中值为1,不选值为0: 解决方案: 插入一行 <input type="hidden" name="RemberPwd" ...
- jQuery radio取值,checkbox取值,select取值
语法解释: $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 var checkTex ...
- jquery ajax post 传递数组 ,多checkbox 取值
jquery ajax post 传递数组 ,多checkbox 取值 http://w8700569.iteye.com/blog/1954396 使用$.each(function(){});可以 ...
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...
- easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $(" ...
- jquery radio取值,checkbox取值,select取值及选中
jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关 获取一组radio被选中项的值 var item = $('in ...
- GridView中实现CheckBox的全选
GridView中实现CheckBox的全选 用服务器端的方法: 在页面上放一个gridview控件,配置好数据源,编辑列, <asp:GridView ID="GridView1&q ...
- C#中float的取值范围和精度
原文:C#中float的取值范围和精度 float类型的表现形式: 默认情况下,赋值运算符右侧的实数被视为 double. 因此,应使用后缀 f 或 F 初始化浮点型变量,如以下示例中所示: floa ...
随机推荐
- 重写OnPaint事件对窗体重绘 实例1
public class WindowOne:Form { public WindowOne() { InitializeCompnent(); } public void InitializeCom ...
- First 5 minutes of SQLite
What is SQLite? SQLite is light-weight RDBMS, it is use the file system rather than the C/S client, ...
- Eclipse MAT: Understand Incoming and Outgoing References
引用:http://xmlandmore.blogspot.hk/2014/01/eclipse-mat-understand-incoming-and.html?utm_source=tuicool ...
- windows下配置svn的https访问
svn是一个功能强大的代码版本管理系统,可以将服务端安装在linux.unix以及windows下.svn通常采用http方式进行代码提交与下载.由于密码采用明文传输,因此存在泄密的风险.若采用htt ...
- Python标准库内置函数——hasattr
hasattr(object, name): # object 对象 name 特征名称 判断对象object是否包含名为name的特性(hasattr是通过调用getattr(ojbect, nam ...
- ognl.NoSuchPropertyException(没有对应属性异常)
ognl.NoSuchPropertyException: com.xie.struts2.tags.modal.Student.sName(没有对应属性异常) at ognl.ObjectPrope ...
- 【笔记】Unix 平台标准
POSIX 表示可移植操作系统接口(Portable Operating System Interface ,缩写为 POSIX ),POSIX标准定义了操作系统应该为应用程序提供的接口标准,是IEE ...
- TypeScript开发Vue
用TypeScript开发Vue——如何通过vue实例化对象访问实际ViewModel对象 目录 背景 解决方案 关于Vue中的计算属性类型 TypeScript的强制类型声明语法 强制类型声明的局限 ...
- OC和C语言的混编注意点和好处
苹果的Objective-C编译器批准用户在统一个源文件里自由地混杂利用C++和Objective-C,混编后的语言叫Objective-C++.有了它,你就能够在Objective-C利用过程中利用 ...
- ftp二进制与ascii传输方式区别
ASCII 和BINARY模式区别: 用HTML 和文本编写的文件必须用ASCII模式上传,用BINARY模式上传会破坏文件,导致文件执行出错. BINARY模式用来传送可执行文件,压缩文 ...