Datatable as Gridview datasource

J

j.zascinski

Hi,
i have a "simple" problem with gridview, please help me :)
i want to have gridview which is binded to a datatable (or a dataset).
i can show the data from the dataset in the gridview and i can start
editing the data, but when i click update i loose my new values. I want
this values to be saved in datatable (not straight to database with
sqldatasource - i tried this and it worked great), i tried to do this
task with objectdatasource but i couldn't make it work :(
can anyone post a little example of how to do this? (i'm searching
googles for a week and still found nothing )

Thanks
Jan Zascinski
 
A

Andrew Robinson

Two ways I can think of to accomplish this:

1. Use the old style DataBind() with a DataSource that is set to a
DataTable. You will have to subscribe to a number of the events on the
GridView such as Editing, Deleting and Selecting and make the changes to
your base DataTable yourself. Using DataBind with a DataSource (not a
DataSourceID) will only allow for one way databinding. The GridView will
read and display your DataTable but you will have to make the updates
yourself.

2. Use an ObjectDataSource that points to your own Data Access layer class
that in turn updates a DataTable that you maintain.

Both methods will require that you somehow persist your data in the
DataTable between postbacks. This is normally done by writing back to a
database but you don't want to do that so you will have to save it somewhere
else which could include application state, session state or in a server
cache. All of these come with their own set of unique advantages and
disadvantages.

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top