Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Every body

I am trying to pass a value form a GridView to a TextBox or a session.
C#
Session["SEmpID"] = GridView1.SelectedRow.FindControl("SubjectID").ToString();

or
C#
TXTTest.Text = GridView1.SelectedRow.FindControl("SubjectID").ToString();

But I always recive the error:
Object reference not set to an instance of an object.

I hope any one can solve it to me.

Thank you
Posted

GridView1.SelectedRow.FindControl("SubjectID") is null.
When you try to cast null to ToString(), you will get an error.

Try to find out why GridView1.SelectedRow.FindControl("SubjectID") is not returning anything.
 
Share this answer
 
Comments
Espen Harlinn 18-Jan-13 11:48am    
Good point :-D
Abhinav S 18-Jan-13 12:03pm    
Thank you.
Hi,

1) Is your given code in GridView1_SelectedIndexChanged() event.

2) Where you set GridView DataSource
if it is in page_load() event then it should be in

C#
if (!IsPostBack) { GridView1.DataSource = "xyzDataset" }



Please mark it as ans & rate if you find it helps you.
Thank You
Asp.Net/C#.Net Help[^]
Hemant Singh
 
Share this answer
 
v2
Comments
Nasser Abu Farah 18-Jan-13 10:50am    
HiI added a button form the edit tiplatte in the grid view. and place the code in the button.

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