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 8463063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:21:43+00:00 2026-06-10T14:21:43+00:00

GridView1I am trying to switch my code on gridview from this: <asp:SqlDataSource ID=dsPar runat=server

  • 0

GridView1I am trying to switch my code on gridview from this:

        <asp:SqlDataSource ID="dsPar" runat="server" ConnectionString="<%$ ConnectionStrings:connstring %>"
        SelectCommand="SELECT ID,  FileNumber, address, phone from myTable ORDER BY ID"  FilterExpression="ID like '%{0}%'">
        <FilterParameters>
        <asp:ControlParameter Name="StreetSrch" ControlID="searchBox" PropertyName="Text" />
        </FilterParameters>
        </asp:SqlDataSource>

to this:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strQuery As String = "SELECT ID,  FileNumber, address, Phone from MyTable WHERE Id LIKE '%@strSearch%'  ORDER BY Id"

        Dim cmd As New SqlCommand(strQuery)
        Dim dt As DataTable = GetData(cmd)
        Dim CheckBoxArray As ArrayList
        If ViewState("CheckBoxArray") IsNot Nothing Then
            CheckBoxArray = DirectCast(ViewState("CheckBoxArray"), ArrayList)
        Else
            CheckBoxArray = New ArrayList()
        End If

        If Not IsPostBack Then
            Gridview1.DataBind()
            Dim CheckBoxIndex As Integer
            Dim CheckAllWasChecked As Boolean = False
            Dim chkAll As CheckBox = DirectCast(GridView1.HeaderRow.Cells(0).FindControl("chkAll"), CheckBox)
rest of code....
End If
End Sub

Finally, below is a snapshot of the markup:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
                OnPageIndexChanging = "OnPaging" HeaderStyle-CssClass = "header" Font-Size = "10pt" 
                 AlternatingRowStyle-BackColor = "#C2D69B" OnRowDataBound = "RowDataBound" AllowSorting="true" 
                 PageSize="20" CssClass="Gridview" 
                 GridLines="None">

I am getting "Object reference not set to an instance of an object." on the following line:

Line 44: Dim chkAll As CheckBox = DirectCast(GridView1.HeaderRow.Cells(0).FindControl(“chkAll”), CheckBox)

Any idea how to resolve this?

Code is very long and I didn’t want to post all of it here. I can post more if needed.

  • 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-06-10T14:21:44+00:00Added an answer on June 10, 2026 at 2:21 pm

    IT is throwing a null reference exception because

    GridView1.HeaderRow.Cells(0).FindControl("chkAll")
    

    doesn’t find a checkbox so it returns null (Nothing) so what you are essentially doing is trying to cast Nothing to a checkbox.

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

Sidebar

Related Questions

i am trying to read from a textbox within a gridview by using this
I am trying to read cells value from asp.net GridView control in Client Site
I am trying to implement a gridview with checkbox column on asp.net (VB). when
I am trying to set my gridview (asp.net) position to absolute when the gridview
I'm trying to sort a list of entities using a GridView in ASP.NET, but
I am trying to fetch values on a GridView with the following code: protected
i'm trying to delete a record in my gridview. for doing this i added
I'm trying to display some data from a Stored Procedure into my GridView .
I have a GridView on an ASP.NET page that I'm trying to bind to
I have an ASP.NET page which houses a Gridview . I am trying to

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.