469,623 Members | 1,313 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

How to hide columns in Datagrid

Hi All,
I am using Data binding with DataGrid. I need to hide column in the grid
using
DataGrid1.Columns(1).Visible = False

But I get the following error message

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

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

Source Error:

Line 119:
Line 120: Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button1.Click
Line 121: DataGrid1.Columns(1).Visible = False
Line 122: End Sub
Line 123:
It seems that Datagrid does not recognize the columns created at runtime.

Any idea how to do this?

Thanks in advance.

Jie
Nov 17 '05 #1
1 14358
I got it. Use
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated

Select Case e.Item.ItemType

Case ListItemType.Header

e.Item.Cells(1).Visible = False

e.Item.Cells(2).Visible = False


End Sub

"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
Hi All,
I am using Data binding with DataGrid. I need to hide column in the grid
using
DataGrid1.Columns(1).Visible = False

But I get the following error message

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

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

Source Error:

Line 119:
Line 120: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Line 121: DataGrid1.Columns(1).Visible = False
Line 122: End Sub
Line 123:
It seems that Datagrid does not recognize the columns created at runtime.

Any idea how to do this?

Thanks in advance.

Jie

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Andrew Chen | last post: by
6 posts views Thread by Das | last post: by
4 posts views Thread by Tim | last post: by
3 posts views Thread by sivaraman.S | last post: by
5 posts views Thread by J | last post: by
1 post views Thread by nuhura01 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.