Thursday, 24 March 2016

GridView custom CSS style and text alignment example in ASP.NET

No comments    
categories: , ,
GridView custom CSS style


Gridview display the database values on GridView Row but we want to custom style add the css for Gridview row,header,paging like below example using asp.net.

                                   DEMO

                    
                           
   CSS 

.SGrid {
    width:auto;
    background-color#fff;
    margin5px 0 10px 0;
    bordersolid 1px #ff006e;
    border-collapse:collapse;
}

.SGrid th {
    padding4px 2px;
    color#fff;
    background:#f17c7c;
    border-leftsolid 1px #ff006e;
    font-size0.9em;
    text-align:center !important;
}
.SGrid td {
    padding2px;
    bordersolid 1px #ff006e;
    color#717171;
    text-align:center !important;
}
.SGrid .alt { background#cec4c4 ; }
.SGrid .pgr { background#424242 ; }
.SGrid .pgr table { margin5px 0; }
.SGrid .pgr td {
    border-width0;
    padding0 6px;
    border-leftsolid 1px #f17c7c;
    font-weightbold;
    color#f17c7c;
    line-height12px;
    background:#fff;
     text-align:center !important;
 }  
.SGrid .pgr a { color:#424242text-decorationnone; }
.SGrid .pgr a:hover { color:#ff006etext-decorationnone; }


  HTML CODING



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">

     /*GRIDVIEW STYLISH*/ 

        .SGrid {
    width:auto;
    background-color#fff;
    margin5px 0 10px 0;
    bordersolid 1px #ff006e;
    border-collapse:collapse;
}

.SGrid th {
    padding4px 2px;
    color#fff;
    background:#f17c7c;
    border-leftsolid 1px #ff006e;
    font-size0.9em;
    text-align:center !important;
}
.SGrid td {
    padding2px;
    bordersolid 1px #ff006e;
    color#717171;
    text-align:center !important;
}
.SGrid .alt { background#cec4c4 ; }
.SGrid .pgr { background#424242 ; }
.SGrid .pgr table { margin5px 0; }
.SGrid .pgr td {
    border-width0;
    padding0 6px;
    border-leftsolid 1px #f17c7c;
    font-weightbold;
    color#f17c7c;
    line-height12px;
    background:#fff;
     text-align:center !important;
 }  
.SGrid .pgr a { color:#424242text-decorationnone; }
.SGrid .pgr a:hover { color:#ff006etext-decorationnone; }

 /*GRIDVIEW STYLISH*/
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <asp:GridView ID="GridView1" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr" CssClass="SGrid"

            runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" PageSize="3">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbcon %>" SelectCommand="SELECT * FROM [register]"></asp:SqlDataSource>
    </div>
    </form>
</body>

</html>



















0 comments:

Post a Comment