Creating Session Values from Gridview?
I have a gridview that has a hidden column called clientID. The gridview itself has a DataKeyName called Prop_ID.
When a user selects a row from the gridview, I store the selected rows key value in a session variable as follows
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Session("PropertyID") = GridView1.SelectedValue
Response.Redirect("~/PagesEDC/aaa.aspx")
End Sub
Q - How do I also store the value of the hidden column in a session variable?
Thanks in advance
Jim
Re: Creating Session Values from Gridview?
You can create an object for the selected row and call the index of the hidden column like so:
VB Code:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim row as GridViewRow.SelectedRow = GridView1.SelectedRow
'set the index of your hidden value here, in my case its the first column, or index 0. Then stores session value
Session("PropertyID") = row.Cells(0).Text
Response.Redirect("~/PagesEDC/aaa.aspx")
End Sub
Hope this helps!!! :thumb:
Re: Creating Session Values from Gridview?
Thanks but no go. Unfortunately the IDE doesn't like .SelectedRow as an attribute of GridViewRow in fact .Selected Row doesn't even appear in the intelisense. Any other ideas?
Re: Creating Session Values from Gridview?
sorry i'm using VS 2005
what version you using?
Re: Creating Session Values from Gridview?
Also show me the code for your SelectedIndexChanged handler please :)
Re: Creating Session Values from Gridview?
I'm using VS 2005 also. The selected index handler is as follows:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Session("PropertyID") = GridView1.SelectedValue
Response.Redirect("~/PagesEDC/aaa.aspx")
End Sub
Re: Creating Session Values from Gridview?
hmm, here's my code that work without intellisense acting up:
VB Code:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim gridrow As GridViewRow = GridView1.SelectedRow
Session.Add("Session", gridrow.Cells(0).Text)
Response.Redirect("~/PagesEDC/aaa.aspx")
End Sub
Re: Creating Session Values from Gridview?
Thanks for the quick reply. I think you're heading in the right directin, but still no success. I tried the following
Dim gridrow As GridViewRow = GridView1.SelectedRow
Session.Add("test", gridrow.Cells(5).Text)
Session.Add("Test2", gridrow.Cells(11).Text)
Session("ClientID") = gridrow.Cells(11).Text
Session("PropertyID") = GridView1.SelectedValue
But in the immediate window it always shows "" as a value as if nothing is being passed into the session variable
I'm somewhat of a rookie so an hand holding is greatly appreciated
Re: Creating Session Values from Gridview?
Session("PropertyID") = GridView1.SelectedValue
you're still not telling it which index to fill this session with
Re: Creating Session Values from Gridview?
Which column of the selectedIndex is the ProperyID in? The first one?
Re: Creating Session Values from Gridview?
Here's what I have done:
In global.asax I have defined the following:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("SessionLanguage") = "en-us"
Session("ClientID") = ""
Session("ClientName") = ""
Session("PropertyID") = ""
End Sub
When I drug in the gridview I assigned its DataKeyNames as PROP_ID, which is a field from my DB
When a row in the gridview is selected it passes the ID from that ruw into the session variable using Session("PropertyID") = GridView1.SelectedValue, and that works fine without any issues.
This is how I was taught to do it, but I was never taught how to reference in a second value