Can't hide column in datagrid

  • Thread starter Thread starter enak
  • Start date Start date
E

enak

I populate a datagrid by setting the datasource to a
datatable. I then, bind them. After that I try to hide the
last column but am not able to. I get an error message.

Here is my code:

Me.dgReport.DataSource = ds.Tables("tFirst")
Me.dgReport.DataBind()
Me.dgReport.Columns(7).Visible = False

Here is the error that I get:

System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the
collection. Parameter name: index


If I take the last line of code out then the page
displayes as expected except for the last column. I tried
to hide column 3 but got the same result.

After the Bind command I looked at the Columns.Count
property and it is 0. Why is this happening and how do I
fix it?

Thanks
enak
 
You should write
Me.dgReport.Tables(0).Columns(7).Visible = False
Then it will work fine.

Sunil TG
 
Back
Top