Datatable From Datagrid

As My ASP.NET page gets refreshed every time i clicked on runat server control having autopostback property true. Now as the view state of the DataGrid i am using is true so it retains all its rows and values. But my datatable which i have declared is initialized so how can i recover my existing datatable from my Datagrid.

Ram Kinkar Pandey
Infopro Inc.
NOIDA, India


Answer this question

Datatable From Datagrid

  • LorenaHE

    Altthough the data is in the grid, the datatable is not.  The viewstate stores the data that is rendered, but not the entire table object.  If you require the datatable, and you want to store it rather than make the extra database call, then you can store it in viewstate manually, or in the session if need be. 

    Why do you need the table if you have the data If you're filtering locally, you'd probably do better to filter on the database, performance wise, although this may mean extra round trips to the DB.


  • SHutch

    > So what is your view shall i keep this in Session/Cache or make a DB trip again

    That's really a decision that needs to be made on a case by case basis.  Where do you see your application using the most resources, in DB round trips, or in the amount of state it stores Will you use a web farm If you're using a web farm, it's almost always better to just call the database again.  Either way, the fact is that SQL Server will filter your data better than .NET will.  Remember, you need to keep the FULL dataset in memory, and then filter it to get the results you want.  That means you're passing more data back in the one query than you need, because some of it is not displayed, it's not needed after you apply your filter.


  • Fred Krusemark

    You are right i use to bind my datagrid with different set of data from same datatable by filtering. And once my datatable is lost i am not able to do it more. So what is your view shall i keep this in Session/Cache or make a DB trip again
    I am just asking which will have better performance i think keeping it in cache will work better but at the same time it will be not be dynamic.

    Thanks for your reply.

  • Datatable From Datagrid