473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

datagrid in a session variable?

Hi all. I have an empty datagrid on my web form. And I
add BoundDataColumn(s) to it through code. But after each
postback, the columns and rows disappear.

As a workabout, I tried to rebind the datagrid to the
dataset (stored in a session variable) on the PageLoad
function which works fine.

But my datagrid has a button-column called EDIT which is
supposed to execute some code. But during the postback,
the rebinding tends to ignore the code that is supposed
to execute.

Thinking that the "rebinding" is the problem, i tried to
store the datagrid itself (not the dataset this time) in
a session variable and recalling the same using

myGrid = (DataGrid) Session["MYGRID"];

but that returned an empty grid again :-(

Any solution? Thanks a lot...
Nov 18 '05 #1
1 3407
Hi,

You don't want to store control instance to session variable. These things
are not meant to work that way. Control instance and its bullding parts
(like columns in DataGrid) are meant to be recreated on every request, they
are not stored to ViewState itself or elsewhere, however their contents &
visible means i.e rows are.

As a solution put the column specifying to happen on every request (initial
request and postback) in Page_Load (or Page_Init). I.e add columns to the
grid despite is it postback or not. Then do the databinding as you would
normally do, inside IsPostBack check and again when you need to rebind the
Grid. Note that this is seperation between databinding and adding columns.
After these steps things should work. Rows are restored from ViewState at
postback and event should work.

If you still have problems, post some code what you have tried to do and
we'll try to help you.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Michelle Stone" <mi********@yahoo.com> wrote in message
news:06****************************@phx.gbl...
Hi all. I have an empty datagrid on my web form. And I
add BoundDataColumn(s) to it through code. But after each
postback, the columns and rows disappear.

As a workabout, I tried to rebind the datagrid to the
dataset (stored in a session variable) on the PageLoad
function which works fine.

But my datagrid has a button-column called EDIT which is
supposed to execute some code. But during the postback,
the rebinding tends to ignore the code that is supposed
to execute.

Thinking that the "rebinding" is the problem, i tried to
store the datagrid itself (not the dataset this time) in
a session variable and recalling the same using

myGrid = (DataGrid) Session["MYGRID"];

but that returned an empty grid again :-(

Any solution? Thanks a lot...

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
2
by: Eric | last post by:
Hi, I've a problem with trying to retrieve a session variable in an include file. Basically, the main asp creates a session variable: <% Session("var1") = "Hello" %> And then when I click...
2
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and...
3
by: Øyvind Isaksen | last post by:
I have a datagrid that displays all files in a folder. It works good, but I need a extra column with a link for choosing image. As shown in the code below I have made an ItemTemplate for this, and...
1
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
4
by: Don Miller | last post by:
I am using a Session variable to hold a class object between ASP.NET pages (in VB). In my constructor I check to see if the Session variable exists, and if it doesn't, I create one and populate it...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
5
by: aamirghanchi | last post by:
Hi, I need to know if anyone else came across this. The Session variable value I set in a sortCommand event handler of a datagrid does not hold on till the next sortcommand event handler and...
7
by: ltarrant | last post by:
Hi, I'm having problems with a DataTable I'm storing in a session variable. I use this as a temporary store for a shopping cart until a customer goes through the checkout and the cart is saved to my...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.