473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to hide auto generate columns in datagrid?

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
8 7295
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Das | last post by:
Hi everyone, I'm using datagrid control to display the data. I want to hide column to be displayed into the data grid. I'm using the code as given below: Method given below is used to bind the...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
4
by: Tim | last post by:
Hi, I am trying to hide the datagrid row header (the left most column that has the 'select' triangle in it which moves with the selected row). It seems to be fairly simple;...
2
by: Thanh Nu | last post by:
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...
1
by: popsovy | last post by:
I am new to the discussion groups and to the .NET world, so this is probably a very basic question.. Is there any quick way in .NET to auto-generate data forms from typed datasets or SQL queries?...
3
by: sivaraman.S | last post by:
Hi friends, How to hide a column in datagrid. regards, Sivaraman.S
5
by: J | last post by:
Ok, they have changed a lot of stuff in VB.net. How in the world do you hide a column on the Datagrid? -- Jason
3
by: Jason | last post by:
How do I hide a column in a GridView in ASP.NET 2.0 when all of the columns are autogenerated based on the datasource? I want to hide the first of three columns, but the following doesn't work: ...
1
by: nuhura01 | last post by:
Hi all.. I have a datagrid in my system and I preview the datagrid in other html page. Below are the code that I'm using: Dim oStringWriter As System.IO.StringWriter = New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.