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 8749579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:43:04+00:00 2026-06-13T12:43:04+00:00

The .NET DataGrid control has an AutoGeneratingColumn Event that fires once for every bound

  • 0

The .NET DataGrid control has an AutoGeneratingColumn Event that fires once for every bound data item right after the data source is changed. This is useful because you could define certain columns in the template, like so:

<Columns>
        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="ww{0}" DataTextField="ID" DataTextFormatString="{0}" HeaderText="ID" />
</Columns>

and then prevent the same column from being replicated when columns are autogenerated from your data source. In this example, you could prevent the ID column from being autogenerated like this:

Private Sub DG_AutoGeneratingColumn(ByVal sender As Object, ByVal e As DataGridAutoGeneratingColumnEventArgs)
    Dim headername As String = e.Column.Header.ToString()
    If headername = "ID" Then
        e.Cancel = True
    End If
End Sub

My question is whether a similar functionality can be achieved with a GridView control.

DETAILS

The data source for the gridview is a DataTable object, which I am binding like so:

    GridView1.DataSource = results.Tables("Vitals")
    GridView1.DataBind()

The number of columns in my DataTable will vary, which is why it is extremely convenient for me to use AutoGenerateColumns.

  • 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-06-13T12:43:05+00:00Added an answer on June 13, 2026 at 12:43 pm

    To do that you should handle the RowCreated event and write something like the following:

    private List<int> hideColumnsIndexes = new List<int>(); 
    
    protected void Page_Load(object sender, EventArgs e)
    {
        hideColumnsIndexes.Clear();
    }
    
    protected void GridView1_OnRowCreated(object sender, GridViewRowEventArgs e)
    {
        //Find indexes
        if (e.Row.RowType == DataControlRowType.Header)
        {
            for (int i = 0; i < e.Row.Cells.Count; i++ )
            {
                if (e.Row.Cells[i].Text == "Id")
                {
                    hideColumnsIndexes.Add(i);
                }
    
                //Add more columns to hide
            }
        }
    
        //Hide cells
        foreach (var index in hideColumnsIndexes)
        {
            e.Row.Cells[index].Visible = false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a VB.Net WinForms application that has multiple data girds on any given
I have a WinForms .NET datagrid whose data source is a List<cLineItem> called lines.
I'm trying to use WPFToolkit's DataGrid control (and C#/.Net 3.5) to display a ComboBox
i used datagrid control in .net platform... but now i am in big confusion
What are the benefits of using a datagrid vs repeater vs ListView control (asp.net
I have a fairly big asp.net website that use GridView bound to the same
I have a asp.net web application with jquery controls. I have a datagrid that
i working on asp.net & C# i have datagrid that contain my database. i
Using .NET 1.1, I have a DataGrid that contains three columns for each row.
MSDN says , The DataGridView control is a new control that replaces the DataGrid

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.