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.
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
Class