DataGrid - Hiding a Column - Not Working

  • Thread starter Thread starter David Freeman
  • Start date Start date
D

David Freeman

Hi There!

Below is my VB.NET code...

Dim strSQL As String

strSQL = "SELECT [Name],[Priority] FROM Customers GROUP BY [Country],
[Priority], [Name]"

Dim oleConn As OleDbConnection = Nothing
Dim oleAdapter As OleDbDataAdapter = Nothing

Dim objDataSet As DataSet = Nothing
Dim strResultTable As String = "Customers"

oleConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Server.MapPath("Test.mdb"))

oleAdapter = New OleDbDataAdapter(strSQL, oleConn)
objDataSet = New DataSet
oleAdapter.Fill(objDataSet, strResultTable)

oleConn.Close()

With myDataGrid

.DataSource = objDataSet.Tables(strResultTable)
.DataBind()

.Columns(1).Visible = False '<< Not Working!!!!

end with

I tried to hide the second column by...

.Columns(1).Visible = False

But the column does not hide! Why?

I've also tried the following in my HTML section...

<asp:DataGrid runat="server" id="myDataGrid">

<Columns>
<asp:BoundColumn DataField="Priority"
Visible="False"></asp:BoundColumn>
</Columns>

</asp:DataGrid>

And still the column does not hide.

This is driving me nuts! Plz help!!!!

Thank you all in advance!

David
 
Hi,

Set the AutoGenerateColumns property (attribute) of the DataGrid to false
and add only the columns you need to be displayed (rendered) to the client.

Hope this helps
Martin Dechev
ASP.NET MVP
 
Hi David

Are your columns generated at runtime (this neat little checkbox on the
datagrid properties page)?
If so, try unchecking it, and adding your columns manually (in the
properties page)

Another options that might work (dunno for sure), is to move the setting of
Visible = False to before the call to DataBind.
This might give you a runtime exception..not sure.

HTH
/HG
 
YO! Martin

Got me there. Just a little earlier than my post.



Martin Dechev said:
Hi,

Set the AutoGenerateColumns property (attribute) of the DataGrid to false
and add only the columns you need to be displayed (rendered) to the client.

Hope this helps
Martin Dechev
ASP.NET MVP
David Freeman said:
Hi There!

Below is my VB.NET code...

Dim strSQL As String

strSQL = "SELECT [Name],[Priority] FROM Customers GROUP BY [Country],
[Priority], [Name]"

Dim oleConn As OleDbConnection = Nothing
Dim oleAdapter As OleDbDataAdapter = Nothing

Dim objDataSet As DataSet = Nothing
Dim strResultTable As String = "Customers"

oleConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Server.MapPath("Test.mdb"))

oleAdapter = New OleDbDataAdapter(strSQL, oleConn)
objDataSet = New DataSet
oleAdapter.Fill(objDataSet, strResultTable)

oleConn.Close()

With myDataGrid

.DataSource = objDataSet.Tables(strResultTable)
.DataBind()

.Columns(1).Visible = False '<< Not Working!!!!

end with

I tried to hide the second column by...

.Columns(1).Visible = False

But the column does not hide! Why?

I've also tried the following in my HTML section...

<asp:DataGrid runat="server" id="myDataGrid">

<Columns>
<asp:BoundColumn DataField="Priority"
Visible="False"></asp:BoundColumn>
</Columns>

</asp:DataGrid>

And still the column does not hide.

This is driving me nuts! Plz help!!!!

Thank you all in advance!

David
 
Thanks!!!

David

Martin Dechev said:
Hi,

Set the AutoGenerateColumns property (attribute) of the DataGrid to false
and add only the columns you need to be displayed (rendered) to the
client.

Hope this helps
Martin Dechev
ASP.NET MVP
David Freeman said:
Hi There!

Below is my VB.NET code...

Dim strSQL As String

strSQL = "SELECT [Name],[Priority] FROM Customers GROUP BY
[Country],
[Priority], [Name]"

Dim oleConn As OleDbConnection = Nothing
Dim oleAdapter As OleDbDataAdapter = Nothing

Dim objDataSet As DataSet = Nothing
Dim strResultTable As String = "Customers"

oleConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Server.MapPath("Test.mdb"))

oleAdapter = New OleDbDataAdapter(strSQL, oleConn)
objDataSet = New DataSet
oleAdapter.Fill(objDataSet, strResultTable)

oleConn.Close()

With myDataGrid

.DataSource = objDataSet.Tables(strResultTable)
.DataBind()

.Columns(1).Visible = False '<< Not Working!!!!

end with

I tried to hide the second column by...

.Columns(1).Visible = False

But the column does not hide! Why?

I've also tried the following in my HTML section...

<asp:DataGrid runat="server" id="myDataGrid">

<Columns>
<asp:BoundColumn DataField="Priority"
Visible="False"></asp:BoundColumn>
</Columns>

</asp:DataGrid>

And still the column does not hide.

This is driving me nuts! Plz help!!!!

Thank you all in advance!

David
 
I'm hand-coding (with WebMatrix) so no properties page :P

Martin's method helped me.

Cheers,
David

HG said:
Hi David

Are your columns generated at runtime (this neat little checkbox on the
datagrid properties page)?
If so, try unchecking it, and adding your columns manually (in the
properties page)

Another options that might work (dunno for sure), is to move the setting
of
Visible = False to before the call to DataBind.
This might give you a runtime exception..not sure.

HTH
/HG


David Freeman said:
Hi There!

Below is my VB.NET code...

Dim strSQL As String

strSQL = "SELECT [Name],[Priority] FROM Customers GROUP BY
[Country],
[Priority], [Name]"

Dim oleConn As OleDbConnection = Nothing
Dim oleAdapter As OleDbDataAdapter = Nothing

Dim objDataSet As DataSet = Nothing
Dim strResultTable As String = "Customers"

oleConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Server.MapPath("Test.mdb"))

oleAdapter = New OleDbDataAdapter(strSQL, oleConn)
objDataSet = New DataSet
oleAdapter.Fill(objDataSet, strResultTable)

oleConn.Close()

With myDataGrid

.DataSource = objDataSet.Tables(strResultTable)
.DataBind()

.Columns(1).Visible = False '<< Not Working!!!!

end with

I tried to hide the second column by...

.Columns(1).Visible = False

But the column does not hide! Why?

I've also tried the following in my HTML section...

<asp:DataGrid runat="server" id="myDataGrid">

<Columns>
<asp:BoundColumn DataField="Priority"
Visible="False"></asp:BoundColumn>
</Columns>

</asp:DataGrid>

And still the column does not hide.

This is driving me nuts! Plz help!!!!

Thank you all in advance!

David
 
Hi David

Martins and mine methods does the same thing - in two different ways -
non-GUI and GUI.

Glad to help.




David Freeman said:
I'm hand-coding (with WebMatrix) so no properties page :P

Martin's method helped me.

Cheers,
David

HG said:
Hi David

Are your columns generated at runtime (this neat little checkbox on the
datagrid properties page)?
If so, try unchecking it, and adding your columns manually (in the
properties page)

Another options that might work (dunno for sure), is to move the setting
of
Visible = False to before the call to DataBind.
This might give you a runtime exception..not sure.

HTH
/HG


David Freeman said:
Hi There!

Below is my VB.NET code...

Dim strSQL As String

strSQL = "SELECT [Name],[Priority] FROM Customers GROUP BY
[Country],
[Priority], [Name]"

Dim oleConn As OleDbConnection = Nothing
Dim oleAdapter As OleDbDataAdapter = Nothing

Dim objDataSet As DataSet = Nothing
Dim strResultTable As String = "Customers"

oleConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Server.MapPath("Test.mdb"))

oleAdapter = New OleDbDataAdapter(strSQL, oleConn)
objDataSet = New DataSet
oleAdapter.Fill(objDataSet, strResultTable)

oleConn.Close()

With myDataGrid

.DataSource = objDataSet.Tables(strResultTable)
.DataBind()

.Columns(1).Visible = False '<< Not Working!!!!

end with

I tried to hide the second column by...

.Columns(1).Visible = False

But the column does not hide! Why?

I've also tried the following in my HTML section...

<asp:DataGrid runat="server" id="myDataGrid">

<Columns>
<asp:BoundColumn DataField="Priority"
Visible="False"></asp:BoundColumn>
</Columns>

</asp:DataGrid>

And still the column does not hide.

This is driving me nuts! Plz help!!!!

Thank you all in advance!

David
 
Back
Top