T
Thanh Nu
Hi,
I would like to hide a column in a web datagrid (with
create columns automatically at runtime checked), and I
cannot refer to the columns collection like this:
DataGrid1.Columns(0).Visible = False
(the message at runtime is something like index out of
range, and under the debuger, I discover that the
attribute count of the columns collection is 0!)
Below is my piece of code.
Could someone help me to solve this problem without
having to bind the datagrid manually, because I have a
sort of generic application, in which I cannot know in
advance the column name.
(Remark : in the catch part, I can manage to hind the
data of the column, but I cannot hide the header, and all
my data columns are shifted left)
Thanks in advance,
------------- Code ------------------
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim msg As String
'Put user code to initialize the page here
SqlConnection1.Open()
Dim rq As String = "select * from Categories"
Dim cmd As New SqlCommand(rq, SqlConnection1)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim objItem As DataGridItem
Dim ThisBackColor As New System.Drawing.Color
DataGrid1.DataSource = dr
DataGrid1.DataBind()
Try
DataGrid1.Columns(0).Visible = False
Catch ex As Exception
For Each objItem In DataGrid1.Items
objItem.Cells(0).Visible = False
Next
End Try
End Sub
I would like to hide a column in a web datagrid (with
create columns automatically at runtime checked), and I
cannot refer to the columns collection like this:
DataGrid1.Columns(0).Visible = False
(the message at runtime is something like index out of
range, and under the debuger, I discover that the
attribute count of the columns collection is 0!)
Below is my piece of code.
Could someone help me to solve this problem without
having to bind the datagrid manually, because I have a
sort of generic application, in which I cannot know in
advance the column name.
(Remark : in the catch part, I can manage to hind the
data of the column, but I cannot hide the header, and all
my data columns are shifted left)
Thanks in advance,
------------- Code ------------------
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim msg As String
'Put user code to initialize the page here
SqlConnection1.Open()
Dim rq As String = "select * from Categories"
Dim cmd As New SqlCommand(rq, SqlConnection1)
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim objItem As DataGridItem
Dim ThisBackColor As New System.Drawing.Color
DataGrid1.DataSource = dr
DataGrid1.DataBind()
Try
DataGrid1.Columns(0).Visible = False
Catch ex As Exception
For Each objItem In DataGrid1.Items
objItem.Cells(0).Visible = False
Next
End Try
End Sub