asp.net - How to add and retrieve rows elements from List in c# -


i using entityframework , in application have defined class in have set properties , values.as there step wise process have declared class list need add rows or properties values @ each step.

    //i have declared class list below      list<processsteps> objsteps = new list<processsteps>();      // step 1      processsteps obj = new processsteps();     obj.id= 1;     obj.name= "v2k";     obj.step=1;     objsteps.add(obj);      // step 2     processsteps obj = new processsteps();     obj.id= 2;     obj.name= "vvk";     obj.step=2;     objsteps.add(obj); 

so @ point need access both id 1 , 2 i'm nnot able objsteps because each time objsteps overwrite previous one. , on debugging shows me count 1.

you should consider asp.net page life cycle, every time application gets request recreate new instance of class (code behind) doesn't matter if have field on class level, redefined each request.

so can preserve state?

there viewstate , session in asp.net webforms can use.

in case maybe this:

public list<processsteps> steps  {         {         if(viewstate["processsteps"] == null)             viewstate["processsteps"] = new list<processsteps>();         return (list<processsteps>)viewstate["processsteps"];     }     set     {         viewstate["processsteps"] = value;     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -