Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6629015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:12:01+00:00 2026-05-25T22:12:01+00:00

I have a standard ASP.NET GridView and I’d like the first column (a emplateField

  • 0

I have a standard ASP.NET GridView and I’d like the first column (a emplateField) to be rendered as <th>, or in ASP.NET terms, I’d like to set it to the GridView RowHeaderColumn property. But that property is looking for the name of a DataItem (from a BoundColumn).

How can I render my TemplateField with <th> tags?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:12:02+00:00Added an answer on May 25, 2026 at 10:12 pm

    Finally found a workaround for this. I am not sure if this code has anything to do with good ASP.NET practices, but it does the trick:

    public class FirstColumnHeaderGridView : GridView
    {
        protected override void InitializeRow(GridViewRow row, DataControlField[] fields)
        {
            DataControlFieldCell cell = new DataControlFieldHeaderCell(fields[0]);
            DataControlCellType header = DataControlCellType.DataCell;
    
            fields[0].InitializeCell(cell, header, row.RowState, row.RowIndex);
            row.Cells.Add(cell);
    
    
            DataControlField[] newFields = new DataControlField[fields.Length - 1];
            for (int i = 1; i < fields.Length; i++)
            {
                newFields[i - 1] = fields[i];
            }
    
            base.InitializeRow(row, newFields);
        }
    }
    

    Let me explain what is going on here. We are creating a special type of GridView, that will render its first column using <th> tags no matter how this column is created. For this we are overriding the InitializeRow method. This method basically configures cells for the row. We are handling the first cell, and let standard GridView take care of the rest.

    The configuration we are applying to the cell is fully taken from the GridView implementation and is enough for the cell to be rendered with <th> tag instead of <td>.

    After that workaround the usage is absolutely standard – register our class as a server control and use it as usual GridView:

    <%@ Register Assembly="WebApplication1" Namespace="WebApplication1" TagPrefix="wa1" %>
    ...
    <wa1:FirstColumnHeaderGridView ID="Grid1" runat="server" ...>
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    Will be inside th
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    Will be inside td
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </wa1:FirstColumnHeaderGridView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly standard ASP.NET GridView that displays 2 columns that have a
I have a custom gridview control that extends the standard asp.net gridview control. The
I have a standard webservice in ASP .Net 4.0 defined like this: [WebMethod] public
I have a standard ASP.NET MVC (RC Refresh) web project, with the standard ASP.NET
I have a standard ASP.NET 2.0 web page with a Delete button on it.
if i have a standard ASP.NET application, is there any difference between making an
I used to have a standard ASP.NET MVC 3 application that was Ninject-wired via
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have a bunch of ASP.NET web pages (that have a standard layout) that
In an ASP.NET 3.5 site we have a relatively standard payment checkout progess that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.