<p>WebGrid Example With textbox and checkbox</p>
<% var list = new[]
{
new { StudentId = 1, Name = "Name1", Cond = true },
new { StudentId = 2, Name = "Name3", Cond = false },
new { StudentId = 3, Name = "Name3", Cond = true },
new { StudentId = 4, Name = "Name4", Cond = true },
new { StudentId = 5, Name = "Name5", Cond = false },
new { StudentId = 6, Name = "Name6", Cond = true },
new { StudentId = 7, Name = "Name7", Cond = true },
new { StudentId = 8, Name = "Name8", Cond = true },
new { StudentId = 9, Name = "Name9", Cond = true },
new { StudentId = 10, Name = "Name10", Cond = true },
new { StudentId = 11, Name = "Name11", Cond = true }
};
WebGrid studentGrid = new WebGrid(list);
%>
<%=
studentGrid.GetHtml(htmlAttributes: new { id = "grid" },
alternatingRowStyle: "altrow",
mode: WebGridPagerModes.All,
firstText: "<<First",
previousText: "<Previous",
lastText: "Last>>",
nextText: "Next >",
columns:
new WebGridColumn[]
{
studentGrid.Column("StudentId", "Id"),
studentGrid.Column("Name", "Name"),
studentGrid.Column(columnName: "Name", header: "Name", format: (item) => Html.TextBox("st")),
studentGrid.Column(columnName: "Name", header: "Name", format: x => Html.CheckBox("ts")),
studentGrid.Column(header: "Action",
format: item =>
{
string span = "<span class=\"1\" id=\"{0}\">{1}<span>";
string action = item.Cond ? "Select" : "Remove";
return Html.Raw(string.Format(span, item.StudentId, action));
}),
studentGrid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Cond })),
studentGrid.Column(format:(item) => Html.ActionLink("Delete", "Delete", null, new {onclick=string.Format("deleteRecord('Cart', '{0}')", item.Cond), @class="Delete", href="JavaScript:void(0)"}))
})
%>