How to set webgrid style in MVC

Styling is one of the main parts of webgrid. Webgrid provide some inbuilt property so that we can easily set the style to webgrid.
Here is example with detail

asp.net mvc - How to set webgrid row style

asp.net mvc – How to set webgrid row style

@model  List<Sample.Models.Student>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style type="text/css">
    .webgrid-table
    {
        font-family: "Trebuchet MS" , Arial, Helvetica, sans-serif;
        font-size: 1.2em;
        width: 100%;
        display: table;
        border-collapse: separate;
        border: solid 1px #98BF21;
        background-color: white;
    }
    .webgrid-table td, th
    {
        border: 1px solid #98BF21;
        padding: 3px 7px 2px;
    }
    .webgrid-header
    {
        background-color: #A7C942;
        color: #FFFFFF;
        padding-bottom: 4px;
        padding-top: 5px;
        text-align: left;
    }
    .webgrid-footer
    {
    }
    .webgrid-row-style
    {
        padding: 3px 7px 2px;
    }
    .webgrid-alternating-row
    {
        background-color: #EAF2D3;
        padding: 3px 7px 2px;
    }
</style>

<h2>Index</h2>

@{
    var grid = new WebGrid(Model);
}

<div  id="gridContent" style=" padding:20px; " >
@grid.GetHtml(
        tableStyle: "webgrid-table",
        headerStyle: "webgrid-header",
        footerStyle: "webgrid-footer",
        alternatingRowStyle: "webgrid-alternating-row",
        selectedRowStyle: "webgrid-selected-row",
        rowStyle: "webgrid-row-style",
        mode: WebGridPagerModes.All,
        columns:
            grid.Columns(
            grid.Column(columnName: "Student Name", header: "Name", format: @<text>@item.Name</text>),
            grid.Column(columnName: "SchoolName", header: "School Name", format: @<text>@item.SchoolName</text> ),
            grid.Column(columnName: "Address", header: "Address", format: @<text>@item.Address</text>),
            grid.Column(columnName: "City", header: "City", format: @<text>@item.City</text>),
            grid.Column(columnName: "State", header: "State", format: @<text>@item.State</text>)
           ))
</div>
 

Note: We have added a class “.webgrid-table td, th” which is not configured in webgrid

Advertisements
This entry was posted in ASP.NET MVC Web Grid, css, MVC and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s