473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create 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.GetType("System.Int32");
dt.Columns.Add(dc);

dc = new DataColumn();
dc.ColumnName = "blog_entry_title";
dc.DataType = System.Type.GetType("System.String");
dt.Columns.Add(dc);

dc = new DataColumn();
dc.ColumnName = "blog_entry_date";
dc.DataType = System.Type.GetType("System.DateTime");
dt.Columns.Add(dc);

SqlConnection loConnection = new
SqlConnection(ConfigurationManager.AppSettings["Data_Connection_String"].ToString());
SqlDataAdapter loAdapter = new SqlDataAdapter("SELECT
blog_entry_id, blog_entry_title, blog_entry_date FROM tbblog_entry
WHERE blog_blog_id = " + giBlogID.ToString() + " AND blog_entry_deleted
= 0 ORDER BY blog_entry_date", loConnection);
loAdapter.Fill(dt);
gvBlogList.DataSource = dt;
gvBlogList.DataBind();
gvBlogList.Columns[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 7164
"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.DataKeys(RowIndex).Item("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
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...
18
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: ...
2
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...
1
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...
9
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
by: Keithb | last post by:
What is the best way to hide a GridView column? Thanks, Keith
2
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, ...
4
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...
0
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...
3
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...
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
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,...
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
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,...
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.