Click here to Skip to main content
14,305,109 members

Passing values from datagrid to another page

Anele Ngqandu asked:

Open original thread
Hi Am trying to pass values from gridView to a textbox in another page and i get the following error

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 10:     protected void Page_Load(object sender, EventArgs e)
Line 11:     {
Line 12:         this.txtPatientName.Text = Request.QueryString["name"].ToString();
Line 13:     }
Line 14: }

Below is the code from my first page

foreach (GridViewRow row in grdAvailableStuff.Rows)
           string name = row.Cells[1].Text;
           string time = row.Cells[2].Text;
           Response.Redirect("AddPatients.aspx?name=" + name.ToString());

Then below is my second page

protected void Page_Load(object sender, EventArgs e)
        this.txtPatientName.Text = Request.QueryString["name"].ToString();


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100