473,657 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HIde a column in GridView using auto-generated columns...

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.Get Type("System.In t32");
dt.Columns.Add( dc);

dc = new DataColumn();
dc.ColumnName = "blog_entry_tit le";
dc.DataType = System.Type.Get Type("System.St ring");
dt.Columns.Add( dc);

dc = new DataColumn();
dc.ColumnName = "blog_entry_dat e";
dc.DataType = System.Type.Get Type("System.Da teTime");
dt.Columns.Add( dc);

SqlConnection loConnection = new
SqlConnection(C onfigurationMan ager.AppSetting s["Data_Connectio n_String"].ToString());
SqlDataAdapter loAdapter = new SqlDataAdapter( "SELECT
blog_entry_id, blog_entry_titl e, blog_entry_date FROM tbblog_entry
WHERE blog_blog_id = " + giBlogID.ToStri ng() + " AND blog_entry_dele ted
= 0 ORDER BY blog_entry_date ", loConnection);
loAdapter.Fill( dt);
gvBlogList.Data Source = dt;
gvBlogList.Data Bind();
gvBlogList.Colu mns[0].Visible = false;

I need the data in the first column later, so I want it returned - I
just don't want to show it in the GridView...

Thanks!

May 5 '06 #1
3 7178
"Jason" <ja************ *@hotmail.com>' s wild thoughts were
released on 5 May 2006 05:29:34 -0700 bearing the following
fruit:
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:
<SNIP>
I need the data in the first column later, so I want it returned - I
just don't want to show it in the GridView...


Wouldn't it be easier just to specify the columns you want
to display and use the DataKeys collection to store your
other data?


Jan Hyde (VB MVP)

--
Did you hear about the guy who blamed arithmetic for his divorce?
His wife put two and two together.

(Art. Moger)

May 5 '06 #2
Jan - thanks for the reply.

What you suggest may be a much better idea. This is my first go 'round
with GridView. So, could you provide an example or point me to an
article that explains how to do this?

Thanks again!
Jason

May 5 '06 #3
Jan Hyde <St***********@ REMOVE.ME.uboot .com>'s wild thoughts
were released on Fri, 05 May 2006 14:54:48 +0100 bearing the
following fruit:
"Jason" <ja************ *@hotmail.com>' s wild thoughts were
released on 5 May 2006 05:29:34 -0700 bearing the following
fruit:
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:

<SNIP>

I need the data in the first column later, so I want it returned - I
just don't want to show it in the GridView...


Wouldn't it be easier just to specify the columns you want
to display and use the DataKeys collection to store your
other data?


Ok, I'm working from memory here so my facts might be a
little off.

Anyhoo - select your datagrid and press f4, find the
property 'DataKeyNames'

Lets say you want to retrieve CustomerID from the database
but don't want to display it in the grid.

Add 'CustomerID' (without quotes) to the DataKeyNames
collection, repeat this for your other fields.

You can retrieve the data with code something like this

GridView1.DataK eys(RowIndex).I tem("CustomerID ")

Jan Hyde (VB MVP)

--
Man walks into a bookshop, picks up two books and goes to the counter.
He cuts the bottom off one trouser leg and hands it to the assistant
saying, "There's a turn-up for the books."

May 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2138
by: Anonieko | last post by:
Hello ASPNET guru's, What is a clean way to go around the problem of displaying a GridView templated column where data can contain Single Quote ( ' )? I maybe too naive, but this is of course a common scenario. Scenario: * My database returns names that can contain single quote.
18
6501
by: Auto | last post by:
Hello, I would like to know how do display an image into a Gridview (ASP.NET 2.0) taken directly from a DataBase, NOT using an URL, like described in this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/GridViewEx06.asp I have NO URL, i have the binary image inside the DB, like the field "Photo" in the table "Employees" of the "NWIND.MDB" DataBase.
2
7248
by: shekar | last post by:
Hi, I am showing data in gridview... But i want to hide one particular column in that gridview but i must not keep that column property visable=false....if i keep false i am getting problem when i am updating the row...becoz that is datakeynames.. any suggesstions plz.... Shekar.
1
2718
by: Sean | last post by:
I have my gridview bound to a objectdatasource control and the only thing I need to hide on the grid is the primary key but I need the key in the dataset that refers to it. With a dynamic approach the column can be hidden at a certian point in the rendering cycle. As I have learned today my grid never offically has a column(0) and I would think anyone who ever uses the gridview would want to hide the primary key! Where/how/when can I...
9
8675
by: ghostwolf | last post by:
Hi, I want to hide a column in the asp:GridView, say one of the column of asp:BoundField. But it is not allowed to put <divinside for setting it display:none. What can I do? Thanks in millions.
1
1450
by: Keithb | last post by:
What is the best way to hide a GridView column? Thanks, Keith
2
18882
by: Keithb | last post by:
I need to hide a GridView's "edit" column if the user's role does not support editing. However, the column's Visible property does not support databinding. Is there a workaround? Thanks, Keith
4
6019
by: Luqman | last post by:
I have populated the Child Accounts and Parent Accounts in a Grid View Control, I want to hide the Select Column of Parent Accounts, but not the Child Accounts, is it possible ? I am using VS 2005 ? Best Regards, Luqman
0
2680
by: gnewsgroup | last post by:
Well, I am trying to use the footer row of a GridView for insertion purpose. There are some articles about this, for example, the gridviewguy.com has an example, which always displays the footer row. I would like to display the footer row, only when a LinkButton "Add New" is clicked. And after the new record is saved to the database, let the footer row disappear. In the LinkButton's click event handler, I simply say:
3
9006
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi, I have a GridView with a checkbox column in it called FromInsight, however this is not bound to the dataset, its value is based on another column from the dataset called sourceid For each row FromInsight = true if (SourceId 0). I try to loop around the gridview and add the value of the checkbox but the column seems to have no checked value, please can you help with this. Thanx in advance Robert
0
8402
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
8829
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...
1
8508
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
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
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.