Dynamically created Datagrids data lost on Postback

  • Thread starter Thread starter ree32
  • Start date Start date
R

ree32

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?
 
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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top