Return updated POCO object attached to GridView control using Reflection
I have a Custom GridView Control derived from ASP GridView Control. Now on all the Forms i have been using my CustomGridView Control.
I attach a List object to DataSource of this CustomGrid, and also store this List into ViewState so that i can manipulate this object when ever grid performs any postback.
Now every time i do insertion, updation and deletion i have to manually write code for Data Manipulation in my all Form. i.e. retrive data from ViewState and then update data or delete data or insert data into that object and store it again into ViewState.
I want a way to automatically write Code in my CustomGridView class object i.e. at one place to take care of this task. My CustomGridView Control should able to update, insert and delete for all my forms without Form writing any code at all.
In the end when its time to save the data into persistent storage i should get the final POCO object from CustomGridView Control.
This can be achieved using reflection but how?
Can you please tell me how can i achieve this task? Or what would be the best开发者_StackOverflow approach that i should follow?
Thanks, Huzefa
I question whether it is best practice to store your underlying datasource within the view state. Have you considered putting this list in the session instead? It would be easier to access and you wouldn't burden your users with inflated page sizes due to overweight viewstate.
If you need to go with your stated approach, could you consider putting the code into a base form instead of trying to wedge it in the gridview? That way you only need to write the code once but it's more reasonable than trying to hack the gridview itself.
精彩评论