Set TemplateColumn visible=false in my code-behind?

Below is my .aspx page:

<asp:TemplateColumn HeaderText=“” visible=false>
<ItemTemplate>
<asp:HyperLink NavigateUrl=’ /></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>

How do the same (set visible=false) in my code-behind (.aspx.vb)?

Thank you.

GridView.Columns(i).Visible = False

Where i is the zero based index of gridview columns. So you would need to know if it is the first column in the gridview (0) or the fourth (3) etc.

If you are unsure of the index but know the header text you could do something like this



For i As Integer = 0 To GridView.Columns.Count - 1
If GridView.Columns(i).HeaderText = "SomeHeaderText" Then

GridView.Columns(i).Visible = False

End If

Next


In addition, if you want to set the visibility of whole itemtemplate which have column[0], column[1],column[2],

do above method 3 times,

as i know, it can not set the visibility to false or true for a specific item template

I got it. Thank you very much. :slight_smile: