By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

datagrid in a session variable?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.