将gridview中的checkbox全选

在aspx页面添加如下js脚本

   < script type = " text/javascript " >
  
// <![CDATA[
   function  CheckAll(oCheckbox)
  {
   
var  GridView2  =  document.getElementById( " <%=GridView1.ClientID %> " );
   
for (i  =   1 ;i  <  GridView1.rows.length; i ++ )
   {
    GridView1.rows[i].cells[
0 ].getElementsByTagName( " INPUT " )[ 0 ].checked  =  oCheckbox.checked;
   }
  }
  
  
// ]]>
   </ script >

gridview中的声明部分代码如下

                 < asp:TemplateField HeaderText = " 选择 " >
                  
< HeaderTemplate >
                  
< input id = " Checkbox2 "  type = " checkbox "  onclick = " CheckAll(this) "  runat = " server "   />< label > 全选 </ label >
                 
</ HeaderTemplate >

                    
< ItemTemplate >
                        
< asp:CheckBox ID = " CheckBox1 "  runat = " server "  Text = " 选择 "   />
                    
</ ItemTemplate >
                
</ asp:TemplateField >

如下图:

http://download1.csdn.net/down3/20070524/24093134446.gif

在一个按钮中判断是否行被选择

 

  for  ( int  i  =   0 ; i  < this .GridView1.Rows.Count; i ++ )
        {
            CheckBox myCb 
=  (CheckBox)( this .GridView1.Rows[i].FindControl( " CheckBox1 " ));
            
if  (myCb.Checked)
            {
                Label lb_nj 
=  (Label)( this .GridView1.Rows[i].Cells[ 1 ].Controls[ 1 ]); // 年级
                Label lb_zybh  =  (Label)( this .GridView1.Rows[i].Cells[ 3 ].Controls[ 1 ]); // 专业编号
                Label lb_zymc  =  (Label)( this .GridView1.Rows[i].Cells[ 2 ].Controls[ 1 ]); // 专业名称
                Label lb_ccbh  =  (Label)( this .GridView1.Rows[i].Cells[ 5 ].Controls[ 1 ]); // 层次编号
                Label lb_ccmc  =  (Label)( this .GridView1.Rows[i].Cells[ 4 ].Controls[ 1 ]); // 层次名称

               
// ……………………
        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值