Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello everybody,

I want to transfer gridview cells values from one page to another. Here I used query string but to shock its working for some fields and for other fields(gridview cell values) its not working.

The page which has gridview I used this syntax:
VB
Public ReadOnly Property email() As String
      Get
          Return GridView1.SelectedRow.Cells(3).Text
      End Get
  End Property

The page where i want to use those values I used this syntax
VB
lblemail.Text = Request.QueryString("email").ToString

Error: Object reference not set to an instance of an object

Thanks for your help..
Posted
Updated 2-Jan-12 21:27pm
v2

blemail.Text = Request.QueryString("email").ToString

Ensure that you have a querystring parameter with the name email.
This appears to be null and converting a null to a string is throwing the error.

To remove the error, you can use Convert.ToString(Request.QueryString("email"));.
This will help you avoid an error when your querystring has no email.

However, nothing will be displayed in the blemail.Text control.
 
Share this answer
 
Comments
mirzamujib 3-Jan-12 3:25am    
Thanks Abhinav,

But where should i give the querystring parameter...
can u plz gime syntax...

thanks again...
Abhinav S 3-Jan-12 3:32am    
You dont need to use the query string syntax. Just use Convert.Tostring instead of ToString().
mirzamujib 3-Jan-12 3:42am    
Thanks Abhinav,

I tried and its shows me null value in my lblemail (label).
Abhinav S 3-Jan-12 5:26am    
So your error is gone.
Now check if you are passing email in the querystring (this is nothing but the URL for the webpage).
Note that query string parameters are case-sensitive.
C#
grdviewLink.NavigateUrl +="&email=" + Me.GridView1.SelectedRow.Cells(3).Text


Add the field to navigate URL...
 
Share this answer
 
v2
Comments
Wendelius 3-Jan-12 15:57pm    
Pre tags added

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