Saturday, 1 July 2017

MVC Webgrid example with paging, sorting & custom Design


public class EmailDetails
        public Int32 ID { get; set; }
        public String EMPID { get; set; }
        public String EMailId { get; set; }
        public String empname { get; set; }
        public String EMAILSTATUS { get; set; }
        public String BCC { get; set; }
        public String CC { get; set; }
        public String EMAILSUBJECT { get; set; }
        public String ATTACHMENT { get; set; }
        public String BODY { get; set; }


 public ActionResult List()
            List<EmailDetails> lst = new List<EmailDetails>();
            DataSet objds = objBLLEmailServices.ExecuteDataset(objBLLEmailServices);
            foreach (DataRow dr in objds.Tables[0].Rows) // loop for adding add from dataset to list<modeldata>
                lst.Add(new EmailDetails
                    ID = Convert.ToInt32(dr["ID"]),
                    EMPID = dr["EMPID"].ToString(),
                    EMailId = dr["EMailId"].ToString(),
                    empname = dr["empname"].ToString(),
                    EMAILSTATUS = dr["EMAILSTATUS"].ToString(),
                    BCC = dr["BCC"].ToString(),
                    CC = dr["CC"].ToString(),
                    EMAILSUBJECT = dr["EMAILSUBJECT"].ToString(),
                    ATTACHMENT = dr["ATTACHMENT"].ToString(),
                    BODY = dr["BODY"].ToString()

            return View(lst);



@using ProjectName.Models;

    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
    @model IEnumerable<EmailDetails>
    WebGrid EmailDetails = new WebGrid(Model, rowsPerPage: 5);
<style type="text/css">
    .bg-info {

<div class="row">
    <div class="table-responsive">

    tableStyle: "table table-bordered  bg - info", // applying style on grid
   rowStyle: "bg-info",
    alternatingRowStyle: "bg-info",
    fillEmptyRows: false,
    //show empty row when there is only one record on page to it will display all empty rows there.
    headerStyle: "bg-info", //applying style.

    footerStyle: "bg-info", //applying style.

    mode: WebGridPagerModes.All, //paging to grid
    firstText: "<< First",
    previousText: "< Prev",
    nextText: "Next >",
    lastText: "Last >>",

    columns: new[]  // colums in grid
        /*EmailDetails.Column(columnName:"Username",header:"User Name"),*/ //the model fields to display
        EmailDetails.Column(columnName:"empname",header:"Emp name"), //the model fields to display
        EmailDetails.Column(columnName:"EMailId",header:"EMail Id", format: (item) => new HtmlString(item.EMailId)),
        EmailDetails.Column(columnName:"EMAILSUBJECT",header:"EMAIL SUBJECT"),

        EmailDetails.Column(columnName:"BODY",header:"BODY", format: (item) => new HtmlString(item.BODY)),


No comments:

Post a Comment

Track your Facebook login attempt

Facebook provides a feature which allows you to see all active sessions from different devices and apps together with the date it was last...