DataGrid - Hiding a Column - Not Working

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
 
M

Martin Dechev

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
 
H

HG

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
 
H

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
 
D

David Freeman

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
 
D

David Freeman

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
 
H

HG

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top