473,794 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7320
Hi,

You could use DataGridColumn' s Visible property.

Cosmin

"Hanson" <he********@hot mail.com> wrote in message
news:un******** *****@TK2MSFTNG P11.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,

AutoGenerateCol umns="false"

<asp:datagrid runat="server" autogeneratecol umns="false">
.....boundcolum ns stuff....
</asp:datagrid>

Autogeneratecol umns, 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********@hot mail.com> schreef in bericht
news:un******** *****@TK2MSFTNG P11.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.column s.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******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

You could use DataGridColumn' s Visible property.

Cosmin

"Hanson" <he********@hot mail.com> wrote in message
news:un******** *****@TK2MSFTNG P11.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 AutoGenerateCol umns to false and dynamically add your columns based on what you have in the datatable.

Cosmin
"Hanson" <he********@hot mail.com> wrote in message news:O9******** ******@TK2MSFTN GP12.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.column s.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******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

You could use DataGridColumn' s Visible property.

Cosmin

"Hanson" <he********@hot mail.com> wrote in message
news:un******** *****@TK2MSFTNG P11.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.ewe ka.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********@hot mail.com> schreef in bericht
news:un******** *****@TK2MSFTNG P11.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.W ebControls.Data GridColumn
For Each dgcol In myDG.Columns
If dgcol.HeaderTex t = "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********@hot mail.com> wrote in message
news:uV******** ******@TK2MSFTN GP10.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.ewe ka.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********@hot mail.com> schreef in bericht
news:un******** *****@TK2MSFTNG P11.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 AutoGenerateCol umns
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.Colum ns(1).Visible = False

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

<asp:DataGrid id="Datagrid1" runat="server" AutoGenerateCol umns="True"
OnItemDataBound ="Datagrid1_OnI temDataBound"/>

Private Sub DataGrid1_ItemD ataBound(s As Object, e As
DatagridItemEve ntArgs)
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
8416
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 data grid with the db: public static void DataGrid(DataGrid DG,string sql) { //Initialize connection with the db
6
5074
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 do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
4
5691
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; this.dgStockMasterSummary.RowHeadersVisible = false; however it doesn't hide it. Hiding the column headers works just fine. Does anyone have any ideas?
2
4310
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 = 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.
1
1967
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? I know that it's possible to generate the DataGrid based on a typed data set, but I am more interested in having a form generated that goes vertically instead of horizontally -- labels on the left and text boxes on the right side... Greatly...
3
1714
by: sivaraman.S | last post by:
Hi friends, How to hide a column in datagrid. regards, Sivaraman.S
5
7814
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
7193
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: DataTable dt = new DataTable(); DataColumn dc; dc = new DataColumn(); dc.ColumnName = "blog_entry_id"; dc.DataType = System.Type.GetType("System.Int32"); dt.Columns.Add(dc);
1
3008
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 System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.