GridView header background color
asp.net give us many way to design gridview. we can format it by setting up it's property value, assign many templates
and after all programmatically. changing gridview design in coding is more useful for user defined design. all visitor's are not like
same color. so based on user type some time we need change the gridview look and feels.
in this example we see how can we change the gridview header row background color programmatically. we trigger a button click event. when someone click the button, gridview change it's header background color. full code is here.
in this example we see how can we change the gridview header row background color programmatically. we trigger a button click event. when someone click the button, gridview change it's header background color. full code is here.
GridViewHeaderBackColor.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
GridView1.HeaderStyle.BackColor = Color.OrangeRed;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>How to set change GridView header background color programmatically in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy; font-style:italic;">GridView Example: Change Header Back Color</h2>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="Select ProductID, ProductName, UnitPrice From Products"
CancelSelectOnNullParameter="false"
>
</asp:SqlDataSource>
<asp:GridView
ID="GridView1"
runat="server"
DataSourceID="SqlDataSource2"
AllowPaging="true"
BackColor="DeepPink"
ForeColor="Snow"
BorderColor="Orange"
AutoGenerateColumns="false"
>
<HeaderStyle
BackColor="Crimson"
Font-Italic="false"
ForeColor="Snow"
/>
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="Product ID" ReadOnly="true" />
<asp:BoundField DataField="Productname" HeaderText="Product Name" />
<asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" />
</Columns>
</asp:GridView>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="Change Header Back Color"
Font-Bold="true"
Height="45"
ForeColor="Crimson"
OnClick="Button1_Click"
/>
</div>
</form>
</body>
</html>

