c# - How do I get Gridview underlying datasource? -
i have gridview in asp.net web application under framework 3.5. binding gridview list. inside grid there update , delete functionalities running fine. save functionality, decided extract list datasource , through loop insert new list database. when tried conventional way returned me null.
i tried following ways retrieve list back.
1. list<myclass> list = (list<myclass>gv.datasource); 2. list<myclass> list = gv.datasource list<myclass>; 3. idatasource idt = (idatasource)gv.datasource; list<myclass> list = (list<myclass>)idt;
but no luck, each time got null.
you cannot retreive datasource once is bound , page served. have few methods available retain datasource though:
- store data before binding in
session
- store data before binding in
viewstate
- fetch data db or whatever data store retrieved originally.
- keep ongoing cache of changes stored somewhere else (eg
session
,viewstate
, etc)
i prefer stay away drag , drop useage of datasources , binding data though.
so in case store list somewhere accessible , manipulate go along , rebind each time. when want 'save' can deal underlying data object (list
) have stored , being used define gui. gridview
not datastore, control present data based on data store.
Comments
Post a Comment