Gridview中添加Checkbox后,无法判断CheckBox的被选中状态?

我在页面上(这个页面继承自母板页)放了一个GridView,里面绑定数据后,添加了一个列,里面放了一个CheckBox,然后在按钮的点击事件中添加了对CheckBox的状态检测,希望如果是选中时,获取选中行的全部信息。
现在的问题是,我无法判断CheckBox是否选中。因为我就是选中后,CheckBox的状态还是false。

怎样才能正常判断CheckBox的状态?

 

页面主要代码如下:

HTML code
   
   
< asp:GridView ID ="GridViewWare" runat ="server" AllowPaging ="True" AllowSorting ="True" CellPadding ="4" ForeColor ="#333333" GridLines ="None" AutoGenerateColumns ="False" onpageindexchanging ="GridViewWare_PageIndexChanging" > < RowStyle BackColor ="#FFFBD6" ForeColor ="#333333" /> < Columns > < asp:BoundField DataField ="WareName" HeaderText ="商品名称" /> < asp:BoundField DataField ="WarePrice" HeaderText ="商品价格" /> < asp:BoundField DataField ="WareStore" HeaderText ="商品库存" /> < asp:BoundField DataField ="WareDetail" HeaderText ="商品信息" /> < asp:TemplateField HeaderText ="购买数量" > < ItemTemplate > < asp:TextBox ID ="txtBuyNumber" Width ="25px" runat ="server" ToolTip ="购买数量" ></ asp:TextBox > < asp:CustomValidator ID ="CVCheckNumber" ControlToValidate ="txtBuyNumber" runat ="server" ErrorMessage ="*" ></ asp:CustomValidator > </ ItemTemplate > </ asp:TemplateField > < asp:TemplateField HeaderText ="购买" > < ItemTemplate > < asp:CheckBox ID ="CheckToBuy" runat ="server" Text ="A" /> </ ItemTemplate > </ asp:TemplateField > </ Columns > < FooterStyle BackColor ="#990000" Font-Bold ="True" ForeColor ="White" /> < PagerStyle BackColor ="#990000" ForeColor ="#FFFFFF" HorizontalAlign ="Center" /> < SelectedRowStyle BackColor ="#FFCC66" Font-Bold ="True" ForeColor ="Navy" /> < HeaderStyle BackColor ="#990000" Font-Bold ="True" ForeColor ="White" /> < AlternatingRowStyle BackColor ="White" /> </ asp:GridView >



后台代码如下:

C# code
   
   
protected void btnBuy_Click( object sender, EventArgs e) { foreach (GridViewRow gvr in this .GridViewWare.Rows) { cWare Ware = new cWare(); CheckBox chb = (CheckBox)gvr.FindControl( " CheckToBuy " ); TextBox txtWareNumber2 = (TextBox)gvr.Cells[ 4 ].FindControl( " txtBuyNumber " ); Ware.WareName = gvr.Cells[ 0 ].Text.ToString(); Ware.WarePrice = gvr.Cells[ 1 ].Text.ToString(); Ware.WareBoughtNumber = txtWareNumber2.Text.ToString(); if (chb.Checked) { TextBox txtWareNumber = (TextBox)gvr.Cells[ 4 ].FindControl( " txtBuyNumber " ); Ware.WareName = gvr.Cells[ 0 ].Text.ToString(); Ware.WarePrice = gvr.Cells[ 1 ].Text.ToString(); Ware.WareBoughtNumber = txtWareNumber.Text.ToString(); } } Response.Write( " <script>alert('OK!')</script> " ); }
 
 
第一次绑定时是否放在在if (!IsPostBack)
  {}里面?
 

 

  • tangxk用户头像
  • tangxk
  • (唐人)
  • 等 级:
#3楼 得分:0回复于:2009-10-28 11:30:47
我暴汗!!!太大意了!!!

弄了半天,没注意在page_load里加个ispostback判断。。。。。。。。

谢谢老兄了!!!一语惊醒梦中人。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值