Last post Jul 04, 2006 02:41 AM by ReyN
Jul 02, 2006 11:21 AM|crippsy|LINK
I am looking to store the value from the selected record in a GridView so that I can Navigate to a new page with this as a session variable.
I have tried many variations of the code (held in the master page) but get a variation of issue. The simplified version of the code below returns and issue that GridView1 is not declared. As you can see from the Sub my gridview is called Grid view1. If I
uncomment the Dim statement for Gridview1 and run the screen i get "Exception Details:
System.NullReferenceException: Object reference not set to an instance of an object"
Protected Sub GridView1_SelectedIndexChanged(ByVal sender
ByVal e As System.EventArgs)
NewText = GridView1.Cells(0)
I have also tried variations on what to put in place of the system.EventsArgs and replacing
"NewText = GridView1.Cells(0)"
"NewText = e.item.Cells(0)"
as I have seen e.item in other examples but the item does not seem to be a member of
System.EventArgs or the other variations I use (i.e
However DataGridItemEventArgs does allow e.items.Cells(0) but returns the error that it "
does not have the same signature as delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs) "
Any advice would be most greatfully recieved
Jul 02, 2006 01:05 PM|e_screw|LINK
Jul 02, 2006 02:54 PM|crippsy|LINK
Thanks for the advice and such a quick responce.
First of all I set I set
NewText = GridView1.SelectedDataKey.Values
and I get an error that GridView1 is not Declared, so in the same sub I set
However it now warns me that
Variable 'GridView1' is used befor it has been assigned a value. A null reference exception could result at runtime.
Which it does.
Could part of the issue be that it is set in the Master page? also another quirk but probably not affect this issue is that this GridView has 2 dataKeys set as it is using two joined tables.
Any further views,?
Thanks in advance.
Jul 02, 2006 03:07 PM|e_screw|LINK
Jul 03, 2006 06:22 PM|crippsy|LINK
Got there in the end thanks to your help. I was using the Findcontrol command, but was doing this in the Master document and not the child document. I have now moved the source to the child document and this now works well.
Many thanks again
Jul 04, 2006 02:41 AM|ReyN|LINK
with DataKeyNames, you can simply use