This documentation is archived and is not being maintained.

DataGridColumn.HeaderStyle Property

Gets the style properties for the header section of the column.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public virtual TableItemStyle HeaderStyle { get; }

Property Value

Type: System.Web.UI.WebControls.TableItemStyle
A TableItemStyle that contains the style properties for the header section of the column. The default value is an empty TableItemStyle.

Use this property to provide a custom style for the header section of the column. Common style attributes that can be adjusted include foreground color, background color, font, and content alignment within the cell. Providing a different style enhances the appearance of the column in the DataGrid control.

The following code example demonstrates how to use the HeaderStyle property to get the style properties for the header section of the column.

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="" >
   <script runat="server">

      ICollection CreateDataSource() 

         // Create sample data for the DataGrid control.
         DataTable dt = new DataTable();
         DataRow dr;

         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));

         // Populate the table with sample values. 
         for (int i = 0; i < 5; i++) 
            dr = dt.NewRow();

            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = 1.23 * (i + 1);


         DataView dv = new DataView(dt);
         return dv;

      void Page_Load(Object sender, EventArgs e) 

         // Load sample data only once, when the page is first loaded. 
         if (!IsPostBack) 
            ItemsGrid.DataSource = CreateDataSource();


      void Button_Click(Object sender, EventArgs e) 

         // Count the number of selected items in the DataGrid control. 
         int count = 0;

         // Display the selected times.
         Message.Text = "You Selected: <br />";

         // Iterate through each item (row) in the DataGrid control and 
         // determine whether it is selected. 
         foreach (DataGridItem item in ItemsGrid.Items)

            DetermineSelection(item, ref count);        


         // If no items are selected, display the appropriate message. 
         if (count == 0)

            Message.Text = "No items selected";



      void DetermineSelection(DataGridItem item, ref int count)

         // Retrieve the SelectCheckBox CheckBox control from the  
         // specified item (row) in the DataGrid control.
         CheckBox selection = (CheckBox)item.FindControl("SelectCheckBox");

         // If the item is selected, display the appropriate message and 
         // increment the count of selected items. 
         if (selection != null)

           if (selection.Checked)
              Message.Text += "- " + item.Cells[1].Text + "<br />";



      void Selection_Change(Object sender, EventArgs e)

         // Set the background color for the header and footer sections  
         // of the first column in the DataGrid control.
         ItemsGrid.Columns[0].HeaderStyle.BackColor = 
         ItemsGrid.Columns[0].FooterStyle.BackColor = 



<head runat="server">
    <title>DataGridColumn HeaderStyle and FooterStyle Example</title>

   <form id="form1" runat="server">

      <h3>DataGridColumn HeaderStyle and FooterStyle Example</h3>

      Select a background color for the header and 
      footer sections of the first column.

      <br /><br />

      <b>Product List</b>

      <asp:DataGrid id="ItemsGrid"

         <HeaderStyle BackColor="#00aaaa">

         <FooterStyle BackColor="#00aaaa">


            <asp:BoundColumn DataField="IntegerValue" 

               <HeaderStyle BackColor="White">

               <FooterStyle BackColor="White">


            <asp:BoundColumn DataField="StringValue" 

            <asp:BoundColumn DataField="CurrencyValue" 

               <ItemStyle HorizontalAlign="Right">


            <asp:TemplateColumn HeaderText="Select Item">


                  <asp:CheckBox id="SelectCheckBox"
                       Text="Add to Cart"





      <br /><br />

      <asp:Button id="SubmitButton"
           OnClick = "Button_Click"

      <br /><br />

      <asp:Label id="Message"

      <hr />

      Header and footer BackColor: <br /> 

      <asp:DropDownList id="List"

         <asp:ListItem Selected="True" Value="White"> White </asp:ListItem>
         <asp:ListItem Value="Silver"> Silver </asp:ListItem>
         <asp:ListItem Value="DarkGray"> Dark Gray </asp:ListItem>
         <asp:ListItem Value="Khaki"> Khaki </asp:ListItem>
         <asp:ListItem Value="DarkKhaki"> Dark Khaki </asp:ListItem>




Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0