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

  • Home
  • SEARCH
  • 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 an asp.net page for a simple blog which looks like <asp:TextBox ID=txtContent
I'm stumped by a seemingly simple problem. In my ASP.NET page, I have a
I have put together a small ASP.NET MVC 2 site that does some very
I have been wondering on how to use ASP.NET Membership together with MVC. The
So I have a layered ASP.NET MVC proof-of-concept application with good separation between presentation
I'd like to use the built in ASP.NET membership and role providers to create
Using asp.net MVC in c#, I am making a call to a stored procedure
I have written a VERY simple MVC application which just displays a single string
Im creating a web application in asp.net visual studio 2008.. in my application, i
So today I started learning ASP.NET. Unfortunately I haven't found any good tutorials online,

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.