data binding - How to delete a Item in a ASP.NET listview and persist the datasource? -


i have collection of objects bind listview this:

   if (!ispostback)         {             list<equipment> persons = new list<equipment>                              {new equipment{itemname = "sworn", itemcount = 7, itemcost = 255},                               new equipment{itemname = "civ", itemcount = 3, itemcost = 80},                               new equipment{itemname = "civ", itemcount = 5, itemcost = 200}};              lvmain.datasource = persons;              bindlist();         } 

i want add/update/delete object collection , submit final data object collection bl when user saves... rather delete/add/update everytime row changed.

so question how maintain state datasource? have tried (delete example)

  protected void lvmain_itemcommand(object sender, listviewcommandeventargs e)     {         switch (e.commandname)         {             case "delete":                 {                     listviewdataitem lvdi = (listviewdataitem)e.item;                     lvmain.items.remove(lvdi);                                     break;                 } 

but nothing. can't rebind datasrouce because @ point datasource null.. assume listview keeps own view state contains data?... guess worse case can hold object collection in session object.. ..

am doing wrong or thinking wrong way?

my suggestion store persons in viewstate, add/edit/remove this.

store in viewstate

viewstate["persons"] = persons; 

get out of viewstate

list<equipment> persons = (list<equipment>)viewstate["persons"]; 

... perform add/edit/remove on object store in viewstate


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -