I need to hold multiple rows in a web grid added from Html Form without saving to database. At last I will insert/update web grid rows to database when user clicks on submit button.
Asked
Active
Viewed 1,266 times
-3
-
Can you share the code of what you have tried so far – Prashant Jul 30 '15 at 07:00
-
you can insert table row using jquery or javascript – Nilesh Gajare Jul 30 '15 at 07:15
1 Answers
0
I can suggest you a way to perform this. Take a List in your controller for the view which contains the webgrid. Now when the user enter the details, you can capture it and save it in this List which is bounded to the webgrid on your view like so:
var ListGrid = new WebGrid(Model.EmployeeListGrid, canSort: true, canPage: true, rowsPerPage: 10");
ListGrid.Pager(WebGridPagerModes.NextPrevious);
@ListGrid.GetHtml(
tableStyle: "webgrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-row-style",
rowStyle: "webgrid-row-style",
columns: ListGrid.Columns(
ListGrid.Column(" ", "S.NO.", @<text>@item.Serial_No</text>),
ListGrid.Column(" ", "Employee Name", @<text>@item.EmployeeName</text>)
));
As you said you have a save button on your page and want to save the data on the click of that button, you can now simply call the event (AJAX or the normal post back event) to save the data to the DB. I hope this gives you the idea.

Prashant
- 966
- 9
- 26
-
THANKS PRASHANT FOR PROMPT REPLY...I WILL SEND YOU RESPONSE AFTER TRYING YOUR SOLUTION – sourabh tiwari Jul 30 '15 at 08:14
-
-
The code I shared above is something I had in my snippet box. I don't have other piece of it. You should try something first and then share your code with us. If there is any problem we can help. – Prashant Jul 30 '15 at 13:09
-
I have tried but when returning partial view or json result from ajax call to controller.It is still not updating web grid.I have posted Codes in my new question [link](http://stackoverflow.com/questions/31724557/ajax-result-not-updating-web-grid-automatically-mvc-4?noredirect=1#comment51385632_31724557) – sourabh tiwari Jul 30 '15 at 13:14