Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7556417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:51:20+00:00 2026-05-30T11:51:20+00:00

I am using checkbox in the gridview header to select all records in the

  • 0

I am using checkbox in the gridview header to select all records in the gridview. this is the code behind method.

<asp:GridView ID="gvP" runat="server" AutoGenerateColumns="false" AllowPaging="false"
AllowSorting="false" DataKeyNames="PmtId" CssClass="list-table" HeaderStyle-CssClass="header"
EnableModelValidation="True">
    <Columns>
    <asp:BoundField DataField="PmtId" HeaderText="PmtId" ReadOnly="True" Visible="false" />
    <asp:TemplateField HeaderText="All" ItemStyle-CssClass="checkbox-col" HeaderStyle-CssClass="checkbox-col">
    <HeaderStyle HorizontalAlign="Center" />
    <HeaderTemplate>
    <input id="chkBoxAll" type="checkbox" onclick='javascript:checkAllBoxes("CLEAR_PT")' />
    </HeaderTemplate>
    <ItemTemplate>
    <asp:CheckBox runat="server" ID="chkSelect" />
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="S/No." ItemStyle-CssClass="seq-col" HeaderStyle-CssClass="seq-col">
    <ItemTemplate>
    <%# Eval("SNo")%>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
</asp:GridView> 

protected void chkSelectAll(string arg)
{
    if (arg.Equals("CLEAR_PT"))
    {
    CheckBox chkAll = gvP.HeaderRow.FindControl("chkBoxAll") as CheckBox;
    if (chkAll.Checked == true)
    {
    foreach (GridViewRow gvRow in gvP.Rows)
    {
    CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect") as CheckBox;
    chkSel.Checked = true;
    }
    }
    else
    {
    foreach (GridViewRow gvRow in gvP.Rows)
    {
    CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect") as CheckBox;
    chkSel.Checked = false;
    }
    }
    }
}

I am getting ‘Object reference not set to an instance of an object’ run time error in the following line.

if (chkAll.Checked == true)

Any Idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:51:21+00:00Added an answer on May 30, 2026 at 11:51 am

    Your checkbox control in header template is html input control. You need to change as ASP.NET check box control. Change as server checkbox control and try. Actually check all and uncheck all can be done in client side javascript. No need postback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a checkbox inside a gridview like this <asp:GridView ID=GridView1 runat=server BorderColor=Blue BorderWidth=1px
I'm currently counting all the checked checkboxes in an asp.net gridview using: $('#cphMain_gdvSalesOrder').delegate('input:checkbox', 'click',
Given a GridView control defined like this: <asp:GridView ID=AttachedFilesGridView runat=server AllowSorting=true AllowPaging=false CellPadding=5 AutoGenerateColumns=false
How to disable asp:TextBox on client-side click on HTML checkbox or server-side asp:CheckBox using
When I select the in the gridview using checkbox, I want it to insert
Using Asp.net and jQuery I have a GridView with a CheckBox column. Right now
I'm using checkbox to select the rows in the gridview. How do I insert
Using VS 2008, I have a Repeater control: <asp:Repeater runat=server ID=storesRep DataSourceID=storeSqlDataSource OnItemDataBound=StoresRep_ItemDataBound> <ItemTemplate>
<asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False Width=596px DataKeyNames=Key > <Columns> <asp:BoundField DataField=Key HeaderText=Key SortExpression=key Visible=False />
I have a gridview that I have added a checkbox column using a templatefield

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.