网格中的页眉复选框不起作用. [英] Header Checkbox in grid not work.

查看:62
本文介绍了网格中的页眉复选框不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用grid的Template字段中的header复选框.但是,当我单击header复选框时,如果未选中,则不检查网格行中的另一个复选框.我想在选中标题复选框时选中所有其他子复选框,而当未选中标题复选框或取消选中子复选框时也取消选中.

我用:

i am using the header checkbox in Template field of the grid.but when i click on header checkbox the other checkbox which is in row of grid not checked if it is not checked. i want to do that when header checkbox is cheked all other child checkbox will be checked and when header checkbox will be not checked or deselect the child checkbox also deselect.

i use :

 <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="10" CellSpacing="11" DataKeyNames="id" EmptyDataText="No Document Found for Selected category Width="100%" AutoGenerateColumns="False"              OnRowDataBound="GridView1_RowDataBound" EditIndex="0" CssClass="grid" 
nrowcreated="GridView1_RowCreated">
 <rowstyle forecolor="#000066" height="25px" />
 <columns>
              
 <asp:TemplateField HeaderText="ID" Visible="false" >
 <itemtemplate>
 <asp:Label ID="lbl_id" runat="server" Text=''<%# Eval("id") %>''>
</itemtemplate>
                                                      
<HeaderStyle Width="10%" />
<itemstyle width="1%" />


 <asp:TemplateField HeaderText="Select Document">
<HeaderTemplate>
<asp:CheckBox ID="cbSelectAll" runat="server" onclick="javascript:SelectAllCheckboxes1(this);"  />
 </HeaderTemplate>
<itemtemplate>
 <asp:Checkbox ID="CheckBox1" runat="server" />          
                                                
  </itemtemplate>
 <itemstyle width="1%" />
 


i use the java script on design page:
<script type="text/javascript">
function SelectAllCheckboxes1(CheckBox1)
{
$(''#<%=GridView1.ClientID%>'').find("input:checkbox").each(function ()
 {
    if (this !=CheckBox1 ) 
    {
        this.checked = CheckBox1.checked;
    }
});
}</columns>

推荐答案

(``#<%= GridView1.ClientID%>'')).find("input:checkbox").each(function () { 如果(this!= CheckBox1) { this.checked = CheckBox1.checked; } }); }</columns>
(''#<%=GridView1.ClientID%>'').find("input:checkbox").each(function () { if (this !=CheckBox1 ) { this.checked = CheckBox1.checked; } }); }</columns>



检查此文章
选择/取消选择GridView内部的所有复选框 [ ^ ]
最好的问候
M.Mitwalli
Hi ,
Check this Article
Selecting / Deselecting all the CheckBoxes Inside a GridView[^]
Best Regards
M.Mitwalli


使用此Java脚本


Use This Java Script


function SelectAll(id) {
         var frm = document.forms[0];

         for (i = 0; i < frm.elements.length; i++) {

             if (frm.elements[i].type == "checkbox") {

                 frm.elements[i].checked = document.getElementById(id).checked;

             }

         }



将此代码用于gridview内的复选框...



Use this Code For Check Box Inside gridview...

<asp:templatefield >
<headertemplate>
<asp:checkbox id="chkSelectAll" runat="server" />
  </headertemplate>
 </asp:templatefield>




添加行数据绑定事件,并在.cs文件中调用此javascript ...




Add Row Data Bound Event and in .cs file call this javascript...

protected void gdvTest_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.Header)
       {
           ((CheckBox)e.Row.FindControl("chkSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("chkSelectAll")).ClientID + "')");

       }
   }


这篇关于网格中的页眉复选框不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆