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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:19:05+00:00 2026-05-25T06:19:05+00:00

I have a simple ASP.NET table like so: <asp:Table id=tbl> <asp:TableHeaderRow id=header> <asp:TableHeaderCell id=hcell1

  • 0

I have a simple ASP.NET table like so:

<asp:Table id="tbl">
    <asp:TableHeaderRow id="header">
        <asp:TableHeaderCell id="hcell1" />
    </asp:TableHeaderRow>
    <asp:TableRow id="row">
        <asp:TableCell id="cell1" />
    </asp:TableRow>
</asp:Table>

The ID’s are made up and the actual table has several more columns. I want to be able to hide any column programmatically from the codebehind (not javascript). Is this possible? At this point I can easily change the markup to be pretty much whatever I want, so I’m open to suggestions.

EDIT: Sorry to be clear. I want to be able to simply hide a column in such a way that if I add a new row I don’t want to have to change any of the code that handles the hiding. The ideal would be something like:

tbl.Columns["ColName"].Visible = false;

Less ideal would be a for/foreach loop that did something similar.

  • 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-25T06:19:06+00:00Added an answer on May 25, 2026 at 6:19 am

    Try using this extension method, it extends the Table class, adding methods to hide columns by index and by the ID of a TableHeaderCell (if one exists):

    Note however, that it does not provide any logic to cater for columns which span other
    columns:

    Examples

    tbl.HideColumn("HeaderID");
    tbl.HideColumn(0);
    

    Class

    public static class TableExtensions
    {
        public static void HideColumn(this Table table, int index)
        {
            foreach (TableRow row in table.Rows)
            {
                if (row.Cells.Count-1 >= index)
                {
                    row.Cells[index].Visible = false;
                }
            }
        }
    
        public static void HideColumn(this Table table, string id)
        {
            int index = 0;
            bool columnFound = false;
    
            if (table.Rows.Count > 1)
            {
                TableHeaderRow headerRow = table.Rows[0] as TableHeaderRow;
                if (headerRow != null)
                {
                    foreach (TableHeaderCell cell in headerRow.Cells)
                    {
                        if (cell.ID.ToLower() == id.ToLower())
                        {
                            columnFound = true;
                            break;
                        }
    
                        index++;
                    }
                }
            }
    
            if(columnFound)
                HideColumn(table, index);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple ASP.NET Web Form that looks a bit like the
I have a simple form with some plain html input like bellow using ASP.NET
say we have simple asp.net repeater, in a row we have one checkbox, one
I have an asp.net page for a simple blog which looks like <asp:TextBox ID=txtContent
I have a simple ASP.NET 3.5 SP1 Web Forms app... I've added the System.Web.Routing
Let's say I have a simple ASP.NET MVC blog application and I want to
I have a fairly simple ASP.NET 2.0 menu control using a sitemap file and
I have a very simple ASP.Net page that acts as a front end for
I have a really simple ASP.NET web application and a web setup project that
I have created a simple Asp.Net custom control which automatically combines all the correct

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.