By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,677 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,677 IT Pros & Developers. It's quick & easy.

how to hide auto generate columns in datagrid?

P: n/a
I have a datagrid control in an aspx page. The datagrid columns will be
dynamically generated according to the pre-page's search condition, I want
to hide some columns in the datagrid. is that anyway to do that?
Nov 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi,

You could use DataGridColumn's Visible property.

Cosmin

"Hanson" <he********@hotmail.com> wrote in message
news:un*************@TK2MSFTNGP11.phx.gbl...
I have a datagrid control in an aspx page. The datagrid columns will be
dynamically generated according to the pre-page's search condition, I want
to hide some columns in the datagrid. is that anyway to do that?

Nov 18 '05 #2

P: n/a
Set in the datagrid,

AutoGenerateColumns="false"

<asp:datagrid runat="server" autogeneratecolumns="false">
.....boundcolumns stuff....
</asp:datagrid>

Autogeneratecolumns, Indicates whether the DataGrid should automatically
generate BoundColumn columns using the data supplied in a data source (the
DataGrid will use all fields in the data source to do so).
Nov 18 '05 #3

P: n/a
Sorry Hanson, i misunderstood the question a bit,
anyway,

use a Visible = False

to make it invisible and not be showed then

"Hanson" <he********@hotmail.com> schreef in bericht
news:un*************@TK2MSFTNGP11.phx.gbl...
I have a datagrid control in an aspx page. The datagrid columns will be
dynamically generated according to the pre-page's search condition, I want
to hide some columns in the datagrid. is that anyway to do that?

Nov 18 '05 #4

P: n/a
Thanks first for your response.

But you might misunderstand my question:

1), The datagrid's column is generated in runtime not in design time, because the columns is depone the pre-page's search condition. only in runtime, when I construct the dataTable, I can know how many columns in the datagrid.
2) I can not access the auto-generated columns (when I debug, it should the datagrid.columns.count=0 ), then I can not set the column's visible value;
Any other help is very appreciated!
"Cosmin Marin" <no****@nospam.ro> wrote in message news:#F**************@TK2MSFTNGP12.phx.gbl...
Hi,

You could use DataGridColumn's Visible property.

Cosmin

"Hanson" <he********@hotmail.com> wrote in message
news:un*************@TK2MSFTNGP11.phx.gbl...
I have a datagrid control in an aspx page. The datagrid columns will be
dynamically generated according to the pre-page's search condition, I want
to hide some columns in the datagrid. is that anyway to do that?

Nov 18 '05 #5

P: n/a
Hi,

As Richard also suggested (and if my understanding is correct this time): set AutoGenerateColumns to false and dynamically add your columns based on what you have in the datatable.

Cosmin
"Hanson" <he********@hotmail.com> wrote in message news:O9**************@TK2MSFTNGP12.phx.gbl...
Thanks first for your response.

But you might misunderstand my question:

1), The datagrid's column is generated in runtime not in design time, because the columns is depone the pre-page's search condition. only in runtime, when I construct the dataTable, I can know how many columns in the datagrid.
2) I can not access the auto-generated columns (when I debug, it should the datagrid.columns.count=0 ), then I can not set the column's visible value;
Any other help is very appreciated!
"Cosmin Marin" <no****@nospam.ro> wrote in message news:#F**************@TK2MSFTNGP12.phx.gbl...
Hi,

You could use DataGridColumn's Visible property.

Cosmin

"Hanson" <he********@hotmail.com> wrote in message
news:un*************@TK2MSFTNGP11.phx.gbl...
I have a datagrid control in an aspx page. The datagrid columns will be
dynamically generated according to the pre-page's search condition, I want
to hide some columns in the datagrid. is that anyway to do that?

Nov 18 '05 #6

P: n/a
Hi Richard,

Thanks for your reply first. However the problem is I can not access the autogenerated columns, and then I can not set the column's visible property.
"Richard" <ri*****@nospam.com> wrote in message news:40***********************@newsreader.eweka.nl ...
Sorry Hanson, i misunderstood the question a bit,
anyway,

use a Visible = False

to make it invisible and not be showed then

"Hanson" <he********@hotmail.com> schreef in bericht
news:un*************@TK2MSFTNGP11.phx.gbl...
I have a datagrid control in an aspx page. The datagrid columns will be
dynamically generated according to the pre-page's search condition, I want
to hide some columns in the datagrid. is that anyway to do that?

Nov 18 '05 #7

P: n/a
You could try something like:

Dim dgcol As System.Web.UI.WebControls.DataGridColumn
For Each dgcol In myDG.Columns
If dgcol.HeaderText = "column to hide" Then dgcol.Visible = False
Next

in Page_Load after calling myDG.DataBind(). That will work with explicity
defined columns. I'm not sure if that works with auto-generated columns.

Good luck!

-Ryan

"Hanson" <he********@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
Hi Richard,

Thanks for your reply first. However the problem is I can not access the
autogenerated columns, and then I can not set the column's visible property.
"Richard" <ri*****@nospam.com> wrote in message
news:40***********************@newsreader.eweka.nl ...
Sorry Hanson, i misunderstood the question a bit,
anyway,

use a Visible = False

to make it invisible and not be showed then

"Hanson" <he********@hotmail.com> schreef in bericht
news:un*************@TK2MSFTNGP11.phx.gbl...
I have a datagrid control in an aspx page. The datagrid columns will be
dynamically generated according to the pre-page's search condition, I want
to hide some columns in the datagrid. is that anyway to do that?

Nov 18 '05 #8

P: n/a
Hi,
found this on http://www.datagridgirl.com/faq.aspx

Question: How do I hide a column in my Datagrid if AutoGenerateColumns
is set to True?

Answer: AutoGenerated columns do not appear in the Datagrid's Columns()
collection, and so the usual method of hiding a Datagrid column will
fail:

'Will NOT work for AutoGenerated columns:
Datagrid1.Columns(1).Visible = False

So the place to handle this is in the ItemDataBound event of the
Datagrid:

<asp:DataGrid id="Datagrid1" runat="server" AutoGenerateColumns="True"
OnItemDataBound="Datagrid1_OnItemDataBound"/>

Private Sub DataGrid1_ItemDataBound(s As Object, e As
DatagridItemEventArgs)
e.Item.Cells(1).Visible = False
End Sub

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.