Using Session Variables in 2008 for gridview control

I have a gridview that I populate on the PageLoad event. Once the page is loaded the data is removed.

For my text box controls, I have used session variables and they keep their assigned session variables, but for list controls, I have not been able to get it to work.

Any ideas?

Chris S.

The code is as follows:

If Not Page.IsCallback And Not Page.IsPostBack Then

	  'Connection and Command Information is defined here
	  'Attempting to populate session gridview with session variable
	  'The key field that I want to query on is PIN_NUMBER
			reader = comm.ExecuteReader()
			gridAddresses.DataSource = reader
			gridAddresses.DataKeyNames = New String() {"PIN_NUMBER"}
			Session("Test") = gridAddresses
			gridAddresses = Nothing
			gridAddresses = DirectCast(Session("Test"), GridView)
		End Try
		'The query is performed if the page is not a PostBack
		'Data is deleted here
	'Page Load is complete
	End If

hmmm. Not sure why you would want to do this… But try loading your data into a dataset and saving that in the Session and then binding the dataset to your gridview. It should work, but there are very few cases where I would recommend saving objects like that into session variables.

I don’t actually want to do it this way, but it seems like my best solution for my limited options.

First, I am going to try as you recommended, loading my data into a dataset and binding the datagrid after that.

Just in case there is a better option, here are the steps in the scenario that I have been trying to resolve; keep in mind, I can’t change my resources, just my code, and this is all internal to our organization:

Multiple users may use one shared machine, and although not ideal may also share one login on a given machine, which means I can’t base inforation on user login. Also, the Database Administrator is not too keen on creating or adding to .ini files.

So the user works through the application in this way:

A user opens a desktop application in Sybase PowerBuilder that is connected to DB2.

The user performs an address search in the desktop application. Once the addresse(s) are obtained, I need to get the address PIN, address, user requesting(I use IP), and the application name to a web page.

I don’t know any way to pass variables from a desktop app to a web app so I insert the users IP, Application Name, and Pin address, and street addresses.

The browser then opens; upon opening, it performs a query on the temp DB2 table and it matches the IP by performing a reverse IP lookup.

Once complete a query is performed in an online GIS(Geographic Information Systems) application it zooms to an address and highlights it.

At this point, the data is deleted in the temp DB2 table to eliminate the possibility of inadverdantly attempting to duplicate information.

During the page load event is where I was attempting to assign session variables, all went well until I needed a list of data which hopefully that will be resolved today.

Hopefully this brings better light to what I am attempting to resolve; if there is a better way of writing the code, I am open to the options. Unfortunately, I know the overall method could be changed completely allowing for more solid code, faster development, and ease of scalability, but the code is all that I have any control over.

Thanks for your help with this.

Chris S.

This worked well. Now all I need to do is program the query to run from the gridview.

Thanks again.

Chris S.

Glad you sorted it out. Ok, well if its not gona be an out facing site, then you can def be more lenient. lol.

I just wondering you you bound your gridview. Then tried to load that into a session and then in the finally block set the gridview to null and then bind it to the session object again? Just for testing I would assume.

Anywayz… Glad you got it working

I didn’t bind the gridview, I bound the dataset like this:
adapter.Fill(dataSet, “MyDataTable”)
“dataSet”) = dataSet
gridAddresses.DataSource = Session(

This worked well, but there are two issues that remain to be resolved, one of which I suspect will turn out to be one of the cons of session variables, but I plan on posting both issues next.

Chris S.