I followed this link http://www.codeproject.com/Tips/615776/WebGrid-in-ASP-NET-MVC This is good for single webgrid, but if i create two webgrids in same page with different number of columns i am getting errors how to solve this issue
@{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow",ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Id", format: (item) => item.GetSelectLink(item.Id)),
grid.Column("Name", format: (item) => item.GetSelectLink(item.Name)),
grid.Column("Description", "Description", style: "description")
))
</div>
@{
var gridsecond = new WebGrid(Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "secondgridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="secondgridContent">
@gridsecond.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: gridsecond.Columns(
gridsecond.Column("Id", format: (item) => item.GetSelectLink(item.Id)),
gridsecond.Column("Name", format: (item) => item.GetSelectLink(item.Name)),
gridsecond.Column("Description", "Description", style: "description"),
gridsecond.Column("Quantity", "Quantity")
))
</div>
When you have multiple WebGrids on the same page, you need to provide each with a unique FieldNamePrefix
and PageFieldName
value. You can do that via its constructor:
var grid1 = new WebGrid(Model1, fieldNamePrefix: "g1", pageFieldName: "p1");
var grid2 = new WebGrid(Model2, fieldNamePrefix: "g2", pageFieldName: "p2");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.