1

it is impossible to hide the cell thus

<% if(link){ %>
            <asp:TableHeaderCell >Action</asp:TableHeaderCell>
        <% } %>

Writes: The blocks of code in this context is not supported.

Creating a new table is too problematic.

Any tips, link or code example would be useful.

EkoostikMartin
  • 6,831
  • 2
  • 33
  • 62
Vayas
  • 213
  • 3
  • 10

2 Answers2

1

Typically all visible/not visible type manipulation should be done with Javascript client side. Using jQuery and pointing to the ID of an element to hide it is trivial. However, since you have decided to use an ASP.NET server side control in the way of a TableHeaderCell, you can change its .Visible property server side in the C# code if you wish:

if (isSomeCondition)
{
  this.TableHeaderCell1.Visible = false;
}

You will have to assign an ID to that control in the markup as well to have it's handle:

<asp:TableHeaderCell id="TableHeaderCell1">

I still heavily opt for a client side approach to hiding elements, and you can still do this with the following syntax:

$('#<%= TableHeaderCell1.ClientID %>').hide();
atconway
  • 20,624
  • 30
  • 159
  • 229
0

If you're using gridview control you can do something like this:

 if (link)
            {
                gridview.Columns[1].Visible = false;
            }
Laziale
  • 7,965
  • 46
  • 146
  • 262