Question: How do I hide a column in my Datagrid if AutoGenerateColumns is set to True?
Answer: AutoGenerated columns do not appear in the Datagrid's Columns() collection, and so the usual method of hiding a Datagrid column will fail:
'Will NOT work for AutoGenerated columns:
Datagrid1.Columns(1).Visible = False
So the place to handle this is in the ItemDataBound event of the Datagrid:
<asp:DataGrid id="Datagrid1" runat="server" AutoGenerateColumns="True" OnItemDataBound="Datagrid1_OnItemDataBound"/>
Codebehind
Private Sub Datagrid1_OnItemDataBound(s As Object, e As DatagridItemEventArgs)
e.Item.Cells(1).Visible = False
End Sub
Robert Dannelly blog, Over the internet you can find me by "robert dannelly blog". The blog is an ongoing blog of my software engineering over technologies C#, VB.NET, Java, React, JavaScript, .NET Core Current, SQL Server 7 - Current Version, GIT, GitHub, Jira, Azure, AWS and HTML5. “I have not failed. I've just found 10,000 ways that won't work.” Thomas A. Edison, please click on all links to help support this blog. Thank you. “As an Amazon Associate, I earn from qualifying purchases.”
Subscribe to:
Post Comments (Atom)
1 comment:
It is reserve, neither it is more, nor it is less
Post a Comment