Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii Team ,

I have a gridview whose page size is 5.

Now The second column of the gridview has got one header template contains header checkbox and item template contains check box .

What i want functionality is on clinking header check box of first page it will check all the rows in all the pages .. but say if i am on page two or 3 , and if i clik on header check box then it should select checkboxes on second pages only .
Posted
Comments
Kornfeld Eliyahu Peter 24-Feb-14 5:05am    
Have you done anything so far? Show some effort (code or searching)! As is it ain't a question...
Nandakishore G N 24-Feb-14 5:27am    
what have you done? ..paste it.
Torakami 24-Feb-14 9:23am    
i have sent you the code i tried .. please check ... last comment of mine
Torakami 24-Feb-14 5:59am    
function SelectAllCheckboxes(chk) {
$('#<%=grdEmployee.ClientID %>').find("input:checkbox").each(function () {
if (this != chk) {
this.checked = chk.checked;
}
});
}

I used this query bt this is selecting only on page level .. not throughout the pages

1 solution

use this sample code


XML
<asp:GridView ID="grddata" runat="server" AutoGenerateColumns="false">
<Columns>
    <asp:TemplateField ItemStyle-Width="20px" HeaderStyle-Width="20px">
        <HeaderTemplate>
            <div style="width: 100%; text-align: left; padding-left: 3px;">
                <asp:CheckBox ID="cbSelectAll" runat="server" onchange="javascript:cbSelectAll(this);" />
            </div>
        </HeaderTemplate>
        <ItemTemplate>
            <div style="width: 100%; text-align: left; padding-left: 1px;">
                <asp:CheckBox ID="cbSelectOne" runat="server" />
            </div>
        </ItemTemplate>
    </asp:TemplateField>
 </Columns>
</asp:GridView>
<script type="text/javascript" language="javascript">
//use Jquery
function cbSelectAll(e)
{
    $("#<%=grddata.ClientID%> tr:gt(0) input:[id*='cbSelectOne']").attr('checked',$(e).find("input:[id*='cbSelectAll']").is(":checked"))
}
</script>
 
Share this answer
 
Comments
Torakami 24-Feb-14 6:13am    
//use Jquery
function cbSelectAll(e) {
debugger;
$("#<%=grdEmployee.ClientID%> tr:gt(0) input:[id*='chkHeader']").attr('checked', $(e).find("input:[id*='chkRow']").is(":checked"))
}

function SelectAll(chk) {
var gridViewCtlId = '<%=grdEmployee.ClientID%>';
var grid = document.getElementById(gridViewCtlId);
var gridLength = grid.rows.length;
for (var i = 1; i < gridLength; i++) {
cell = grid.rows[i].cells[1];
for (var j = 0; j < cell.childNodes.length; j++) {
if (cell.childNodes[j].type == 'checkbox') {
cell.childNodes[j].checked = chk;
}
}
}
}

tried with this two .. not working for all pages .. its working page level only
Torakami 24-Feb-14 9:22am    
I tried this way ...

but not able to get it how to find checkbox in this ..

protected void btnSelectAll_Click(object sender, EventArgs e)
{
//Change gridview to
grdEmployee.AllowPaging = false;
grdEmployee.DataBind();

//Transfer rows from GridView to table
for (int i = 0; i < grdEmployee.Rows.Count; i++)
{
if (grdEmployee.Rows[i].RowType == DataControlRowType.DataRow)
{
for (int j = 0; j < grdEmployee.Rows[0].Cells.Count; j++)
{
//Add your code here..



}
}
}

//After filling your datatable change gridview paging style back to first, ie.

grdEmployee.AllowPaging = true;
grdEmployee.DataBind();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900