469,926 Members | 1,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Dynamically created Datagrids data lost on Postback

I have a placeholder and depending on a user input(a drop downlist)
when the user clicks a button I dynamically create a number of
datagrids and fill them with data from a database. But the problem is
that on a postback I lose all the datagrids and their data.

I have looked at numerous pages on the net regarding this issue. Many
say you have to rebuild build the controls on postback. How am I meant
to do this in my situation as I don't even know the number of
datagrids that are going to be built. I also don't want to access the
database and retrieve the data on every single postback.

Is there some way to load the datagrids back?
Nov 19 '05 #1
1 2173
If you build the datagrid dynamically, then you bear the burden of
re-creating the datagrid on a postback. If you do no want to "re-retrieve"
the data from the database, then you can store off the DataTable into a
ViewState variable then on post-back, retrive the datatable from the
Viewstate (eg. MyDataTable = (DataTable) ViewState("MyTable") (C# code
example).

I hope this helps..

"ree32" wrote:
I have a placeholder and depending on a user input(a drop downlist)
when the user clicks a button I dynamically create a number of
datagrids and fill them with data from a database. But the problem is
that on a postback I lose all the datagrids and their data.

I have looked at numerous pages on the net regarding this issue. Many
say you have to rebuild build the controls on postback. How am I meant
to do this in my situation as I don't even know the number of
datagrids that are going to be built. I also don't want to access the
database and retrieve the data on every single postback.

Is there some way to load the datagrids back?

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.