How do I style to GridView with CSS?

I want to use CSS style in GridView instead of itemstyle,header style... available in gridview, Is is possible and How?

Following sample code shows how to apply css style to GridView.

Run sample code

 

<%@ Page Language="C#"%>
<%@ Import Namespace="System.Collections.Generic"%>

<script runat="server">

    
    protectedvoid Page_Load(object sender, EventArgs e)
    {
        List<Account> data =new List<Account>();
        data.Add(new Account("Tom",12002));
        data.Add(new Account("Sam", 8900));
        data.Add(new Account("Harry", 15558));

        gridView.DataSource = data;
        gridView.DataBind();
        
    }

    publicclass Account
    {
        public Account(string name,decimal amount)
        {
            this.name = name;
            this.amount = amount;
        }
        
        privatestring name;
        private decimal amount;
        

        public decimal Amount{
            get { return amount; }
            set { amount = value; }
        }
	
        publicstring Name{
            get { return name; }
            set { name = value; }
        }
	
    }
    
    
</script>
<html >
<head id="Head1" runat="server">
    <title>GridView Summary</title>
    <style type="text/css">
        TABLE.tabulardata {
	        BACKGROUND-COLOR: #74aefa;
        }
        TABLE.tabulardata TR {
	        BACKGROUND-COLOR: white;
        }
        TABLE.tabulardata TH {
	        BACKGROUND-COLOR: blue;
	        PADDING:4px;
        }
        TABLE.tabulardata TD {
	        PADDING:4px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView runat="server" ID="gridView" 
                      CSSClass="tabulardata" CellSpacing="1" 
                      GridLines="None"/>
    </div>
    </form>
</body>
</html>
Bookmark with:
Technorati   Digg   Delicious   StumbleUpon   Facebook
My name is Jigar Desai I share my ideas on this site and you can contact me by filling contact form.

Categories