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:

  1. store data before binding in session
  2. store data before binding in viewstate
  3. fetch data db or whatever data store retrieved originally.
  4. 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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -