|
-
Apr 26th, 2006, 11:26 AM
#1
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2006, 12:07 PM
#2
Fanatic Member
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!!!
Last edited by drpcken; Apr 26th, 2006 at 01:31 PM.
Reason: code typo

In the unlikely event that I answer your question correctly, please Rate my post
Using Visual Studio 2005 Professional 
-
Apr 26th, 2006, 03:48 PM
#3
Thread Starter
Hyperactive Member
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?
-
Apr 26th, 2006, 03:52 PM
#4
Fanatic Member
Re: Creating Session Values from Gridview?
sorry i'm using VS 2005
what version you using?

In the unlikely event that I answer your question correctly, please Rate my post
Using Visual Studio 2005 Professional 
-
Apr 26th, 2006, 03:56 PM
#5
Fanatic Member
Re: Creating Session Values from Gridview?
Also show me the code for your SelectedIndexChanged handler please

In the unlikely event that I answer your question correctly, please Rate my post
Using Visual Studio 2005 Professional 
-
Apr 26th, 2006, 04:12 PM
#6
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2006, 04:16 PM
#7
Fanatic Member
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

In the unlikely event that I answer your question correctly, please Rate my post
Using Visual Studio 2005 Professional 
-
Apr 26th, 2006, 04:42 PM
#8
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2006, 04:46 PM
#9
Fanatic Member
Re: Creating Session Values from Gridview?
Session("PropertyID") = GridView1.SelectedValue
you're still not telling it which index to fill this session with

In the unlikely event that I answer your question correctly, please Rate my post
Using Visual Studio 2005 Professional 
-
Apr 26th, 2006, 05:00 PM
#10
Fanatic Member
Re: Creating Session Values from Gridview?
Which column of the selectedIndex is the ProperyID in? The first one?

In the unlikely event that I answer your question correctly, please Rate my post
Using Visual Studio 2005 Professional 
-
Apr 26th, 2006, 05:26 PM
#11
Thread Starter
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|