I am facing a little problem here....I need a datagrid control, which is maintained at client side (user will edit the grid at the client side in an overlay control with no interaction with the server, I will use javascript to add/edit rows here)....so when user hits the save button (it will be an ajax call) on the form I want the whole data in this grid (the grid will have less than 50 rows) to get submit to the server. I am using a grid from the component art tool which only sends back the rows which were added or edited. I don't want this. So, I am thinking to use the asp.net gridview. I am not sure if asp.net gridview does this or not. Does any body know about this or a better way to achieve what I am trying to do???
+1
A:
A GridView
would work, as it uses ViewState
to maintain its information. During the postback you can access all records, including changed and unchanged values.
There would be multiple ways to solve the AJAX requirements when editing the grid. The simplest solution would be to wrap the grid in an UpdatePanel
and hook into the GridView event of choice, such as GridView.RowUpdated, GridView.RowDeleted, etc. All of the actions handled by the server via an asynchronous postback will be seamless to the user with no ugly flicker, etc.
Sample markup:
<asp:UpdatePanel UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="MyGridView" runat="server" OnRowUpdated="MyGridView_RowUpdated" .. />
</ContentTemplate>
</asp:UpdatePanel>
Code behind:
protected void MyGridView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
//do what you need with the affected row, etc.
}
With the above you would still need to determine how to store the data, and bind, etc. based on your requirements...
KP
2010-02-03 15:52:38
Thanks for the reply. I guess I still have a unsolved problem. Initially there is no record in the database on the page where user is. User fills in some fields and hits submit and if input fields have some invalid data then I can't save this record to the database so I will send it back to the client reporting errors. Now when user corrects the errors and resubmits the page again (he may not edit the datagrid this time) then the update/insert grid function will not be called for any row which was not updated this time, so this data will be lost.
2010-02-03 16:10:45
If you used the GridView, then each record could be saved in the database and rebound during postback. Should another record be added with errors, the first is not lost. This is a common .net design pattern. I'm not sure why it wouldn't work for you...
KP
2010-02-03 16:18:25
A record is composed from a lot of input fields and 2 or 3 data grids and we will be adding more thing to this record with time. I can't save a record in the database (nothing will be saved to the database unless you correct the record) if the record has errors because there are about 15 tables which will be affected when I add a new record. What if the database doesn't allow the values from some input fields and it will totally reject that record.
2010-02-03 16:49:48
Yeah sounds like you have your hands full with this one. Good luck! :)
KP
2010-02-04 14:56:39
Thanks for your help. I actually decided to go with postback instead of AJAX and that solves everything.
2010-02-08 23:31:53