invisible..
ASP.NET
2
Posts
2
Posters
0
Views
1
Watching
-
hy i habve a datagrid and i wanth to make some columns invisible and "Datagrid.Columns(2).visible = False" isn't working.. Can someone tell me why or show me another way 2 do this? i am using vs 2005 plz help 10x
I usually do this in the GridView's RowDataBound event. (Or if you are indeed using a DataGrid instead of the GridView it is the ItemDataBound event. Personally, I don't use the old DataGrid objects anymore.) For a GridView the code would look something like this:
Protected Sub GridView1\_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Select Case e.Row.RowType Case DataControlRowType.DataRow e.Row.Cells(0).Visible = False End Select End Sub
In this example I am hiding the first column in the grid only. If you need to hide another you would need to know the column index and add another statement like this:
e.Row.Cells(index).Visible = False
Hope this helps.