Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. GridView - NullReferenceException

GridView - NullReferenceException

Scheduled Pinned Locked Moved ASP.NET
helptutorialdatabaseworkspace
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ffowler
    wrote on last edited by
    #1

    Hello All, I am stuck on a very simple problem and I at a loss at this point. I have checked the message board but could not find a solution to my particular problem so that is why I am coming to you today. Here goes: I have a very simple page with a 2 GridViews and a text box (simple master/detail setup). The first Gridview is bound to an SQLDataSource which runs a simple stored procedure and fills the gridview upon it's first load. The gridview has a Selection link on it which when clicked passes an argument to the second gridview which is then populated with the details of the selected row. Here's the problem, I want to capture another field of the selected row an show it in a textbox. Simple. Not so (for me anyways). In the Page_Load and SelectedIndexChanged event I simply have 'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();' The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview. Can someone be kind enough to guide me in the right direction on how to cure this ill. Greatly appreciated.....FF

    N S A 3 Replies Last reply
    0
    • F ffowler

      Hello All, I am stuck on a very simple problem and I at a loss at this point. I have checked the message board but could not find a solution to my particular problem so that is why I am coming to you today. Here goes: I have a very simple page with a 2 GridViews and a text box (simple master/detail setup). The first Gridview is bound to an SQLDataSource which runs a simple stored procedure and fills the gridview upon it's first load. The gridview has a Selection link on it which when clicked passes an argument to the second gridview which is then populated with the details of the selected row. Here's the problem, I want to capture another field of the selected row an show it in a textbox. Simple. Not so (for me anyways). In the Page_Load and SelectedIndexChanged event I simply have 'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();' The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview. Can someone be kind enough to guide me in the right direction on how to cure this ill. Greatly appreciated.....FF

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Well, writing the above code in page load doesn't make sense. When the page loads first time, SelectedRow will be NULL. Is this throwing error when you use it in the selected index changed event? :)

      Navaneeth How to use google | Ask smart questions

      F 1 Reply Last reply
      0
      • N N a v a n e e t h

        Well, writing the above code in page load doesn't make sense. When the page loads first time, SelectedRow will be NULL. Is this throwing error when you use it in the selected index changed event? :)

        Navaneeth How to use google | Ask smart questions

        F Offline
        F Offline
        ffowler
        wrote on last edited by
        #3

        Well I hope I am not the only one who has ever done this, I have faith that I am not. But, I thought about just what you replied Navaneeth, and realized the code in the page_load didn't make sense. So I removed it but the SelectedIndexChanged event never fired. So I (just now) reviewed the event. I works now because I put the code in the GridView1 event as opposed to the "GridView2" event. Thanks for your reply and I shall bow out humbly now...

        1 Reply Last reply
        0
        • F ffowler

          Hello All, I am stuck on a very simple problem and I at a loss at this point. I have checked the message board but could not find a solution to my particular problem so that is why I am coming to you today. Here goes: I have a very simple page with a 2 GridViews and a text box (simple master/detail setup). The first Gridview is bound to an SQLDataSource which runs a simple stored procedure and fills the gridview upon it's first load. The gridview has a Selection link on it which when clicked passes an argument to the second gridview which is then populated with the details of the selected row. Here's the problem, I want to capture another field of the selected row an show it in a textbox. Simple. Not so (for me anyways). In the Page_Load and SelectedIndexChanged event I simply have 'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();' The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview. Can someone be kind enough to guide me in the right direction on how to cure this ill. Greatly appreciated.....FF

          S Offline
          S Offline
          saanj
          wrote on last edited by
          #4

          At the time when the page gets loaded, do you think that the GridView1 has any selected row? The problem lies here.

          There is no foolish question, there is no final answer...

          1 Reply Last reply
          0
          • F ffowler

            Hello All, I am stuck on a very simple problem and I at a loss at this point. I have checked the message board but could not find a solution to my particular problem so that is why I am coming to you today. Here goes: I have a very simple page with a 2 GridViews and a text box (simple master/detail setup). The first Gridview is bound to an SQLDataSource which runs a simple stored procedure and fills the gridview upon it's first load. The gridview has a Selection link on it which when clicked passes an argument to the second gridview which is then populated with the details of the selected row. Here's the problem, I want to capture another field of the selected row an show it in a textbox. Simple. Not so (for me anyways). In the Page_Load and SelectedIndexChanged event I simply have 'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();' The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview. Can someone be kind enough to guide me in the right direction on how to cure this ill. Greatly appreciated.....FF

            A Offline
            A Offline
            Abhijit Jana
            wrote on last edited by
            #5

            ffowler wrote:

            In the Page_Load and SelectedIndexChanged event I simply have 'this.TextBox1.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();' The SelectedIndexChanged Event doesn't fire before the postback because I get an error in my Page_Load event that there is a NullReferenceException on the Gridview.

            Check Selected Row index for null before the statement.

            cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups