CheckBox全选/全消设置和GridView自增序号

ASP.NET GridView全选功能实现
本文介绍如何在ASP.NET的GridView控件中实现全选功能。通过自定义JavaScript函数CheckAllSelect()来同步所有复选框的状态,并利用ASP.NET的内置控件GridView展示数据。此外,还提供了对每一项数据进行操作的功能。
<script language="javascript" type="text/javascript">
 function CheckAllSelect()
 {
  var iRowCount=<%=grvApply.Rows.Count%>;
  
  var isCheckked = document.all.chkAllSelect.checked;
  
  for(i= 1;i<=iRowCount;i++ )
  {
   if(typeof(document.all.grvApply.rows(i).cells(0).children(0)) == "object")
   {                                                                      
    document.all.grvApply.rows(i).cells(0).children(0).checked = isCheckked;   
   }
  }
 }
</script>


<asp:GridView ID="grvApply" runat="server" SkinID="AlarmSkin" AutoGenerateColumns="False" OnRowDataBound="grvApply_RowDataBound" OnSelectedIndexChanging="grvApply_SelectedIndexChanging">
 <Columns>
  <asp:TemplateField HeaderText="&lt;input type='checkbox' id='chkAllSelect' title='全选/全消' onClick='CheckAllSelect();' &gt;">
   <ItemTemplate>
    <asp:CheckBox ID="chkBoxSelect" runat="server" />
   </ItemTemplate>
   <ItemStyle Width="20px" />
  </asp:TemplateField>
  <asp:TemplateField HeaderText="序号">
   <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text="<%# Container.DataItemIndex + 1%> "></asp:Label>
   </ItemTemplate>
   <ItemStyle Width="30px" />
  </asp:TemplateField>
  <asp:BoundField DataField="UserCode" HeaderText="用户名" />
  <asp:BoundField DataField="CourCode" HeaderText="课程编号" />
  <asp:BoundField DataField="CourName" HeaderText="课程名" />
  <asp:BoundField DataField="ApplyDate" HeaderText="申请日期" />
  <asp:BoundField DataField="ApplyStatus" HeaderText="申请状态" />
  <asp:TemplateField HeaderText="操作">
   <ItemTemplate>
    <asp:LinkButton ID="lblAccept" runat="server" CommandName="Select">受理</asp:LinkButton>
   </ItemTemplate>
  </asp:TemplateField>
 </Columns>
</asp:GridView>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值