Skip to content

Instantly share code, notes, and snippets.

@sphingu
Created June 18, 2013 13:30
Show Gist options
  • Save sphingu/5805365 to your computer and use it in GitHub Desktop.
Save sphingu/5805365 to your computer and use it in GitHub Desktop.
WebGrid in MVC
@{
var grid = new WebGrid(Model.Select((item, index) => new { Index = index+1, Element = item }), defaultSort: "First Name", canSort: true, canPage: true, rowsPerPage: ViewBag.PageSize, ajaxUpdateContainerId: "grid");
}
@grid.GetHtml(htmlAttributes: new { id = "grid" }, fillEmptyRows: false, tableStyle: "webGrid", headerStyle: "header", footerStyle: "footer", rowStyle: "rowcss", alternatingRowStyle: "alterrowcss",
selectedRowStyle: "selectedRow",
columns: grid.Columns(
grid.Column(columnName: "Index", header: "Sr No."),
grid.Column("Element.strSurnameEN", "Name", @<text><i data-val='@item.Element.ID'>@Convert.ToString(item.Element.strSurnameEN + " " + item.Element.strNameEN + " " + item.Element.strRelativeEN)</i></text> ),
grid.Column("Element.dtDOB", "DOB", item => item.Element.dtDOB != null ? item.Element.dtDOB.ToString("dd/MM/yyyy") : ""),
grid.Column("Element.bitHindiPRAN", "Print Language", item => item.Element.bitHindiPRAN ? "HINDI" : "ENGLISH"),
grid.Column("Element.intSex", "Gender", item => item.Element.intSex == 0 ? "Male" : (item.Element.intSex == 1 ? "Female" : "Other")),
grid.Column(header: "Documents", format: item => Html.ActionLink("Total : " + ((IEnumerable<NPS.Models.tbSubscriberKYCDetail>)item.Value.Element.tbSubscriberKYCDetails).Count(o => o.intStatus == 1), "Index", "Doc", new { item.Element.ID }, new { id = "documentLink", @class = "linkcss" }))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment