473,492 Members | 4,279 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to remove/make invisible autogenerated gridview column

Hi

I've just moved from asp.net 1.1 to 2.0 so am new to gridviews and have a
problem.

I've got a gridview on a form in a web layer project. It has an
objectdatasource object which calls a method in a class in a seperate data
layer project.Therefore the columns are autogenerated. The problem I've got
is that the data that fills the gridview has an "id" column which I don't
want to display but I do want to use programmatically. I've tried hiding &
removing the column but, wherever I put the code, I get an "Argument out of
range" error. My code is:

Me.UserGridView.Columns.RemoveAt(1)

I've tried this in Page Load, Page LoadComplete etc etc.... to no avail.
There is no code on the page to populate the GridView, it's all done through
VisualStudio's ObjectDataSource object properties.

Any clues on how to resolve this would be greatly appreciated.

Thanks
Julia
Oct 2 '08 #1
2 2805
You can do it in RowCreated event. Don't remove columns, just hide them with
e.Item.Cells(1).Visible = false.

In any case, put "id" in DataKeyNames, otherwise you won't find in in
postbacks.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:A0**********************************@microsof t.com...
Hi

I've just moved from asp.net 1.1 to 2.0 so am new to gridviews and have a
problem.

I've got a gridview on a form in a web layer project. It has an
objectdatasource object which calls a method in a class in a seperate data
layer project.Therefore the columns are autogenerated. The problem I've
got
is that the data that fills the gridview has an "id" column which I don't
want to display but I do want to use programmatically. I've tried hiding &
removing the column but, wherever I put the code, I get an "Argument out
of
range" error. My code is:

Me.UserGridView.Columns.RemoveAt(1)

I've tried this in Page Load, Page LoadComplete etc etc.... to no avail.
There is no code on the page to populate the GridView, it's all done
through
VisualStudio's ObjectDataSource object properties.

Any clues on how to resolve this would be greatly appreciated.

Thanks
Julia
Oct 2 '08 #2
Thanks for this. Unfortunately I still get the same error.

I had to use e.Row.Cells(1).Visible = False

Item is not a member of the argument.

Any ideas where I'm going wrong?

Julia
"Eliyahu Goldin" wrote:
You can do it in RowCreated event. Don't remove columns, just hide them with
e.Item.Cells(1).Visible = false.

In any case, put "id" in DataKeyNames, otherwise you won't find in in
postbacks.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:A0**********************************@microsof t.com...
Hi

I've just moved from asp.net 1.1 to 2.0 so am new to gridviews and have a
problem.

I've got a gridview on a form in a web layer project. It has an
objectdatasource object which calls a method in a class in a seperate data
layer project.Therefore the columns are autogenerated. The problem I've
got
is that the data that fills the gridview has an "id" column which I don't
want to display but I do want to use programmatically. I've tried hiding &
removing the column but, wherever I put the code, I get an "Argument out
of
range" error. My code is:

Me.UserGridView.Columns.RemoveAt(1)

I've tried this in Page Load, Page LoadComplete etc etc.... to no avail.
There is no code on the page to populate the GridView, it's all done
through
VisualStudio's ObjectDataSource object properties.

Any clues on how to resolve this would be greatly appreciated.

Thanks
Julia

Oct 2 '08 #3

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

Similar topics

15
3733
by: John Blair | last post by:
Hi, Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist....
0
1727
by: Luis Esteban Valencia | last post by:
Once a user clicks "add new row", a new row is created in my Datagrid. The datasource is huge so they have to scroll to the bottom of the page to edit the data in the new row. I have come across...
9
6085
by: Steve | last post by:
How I can remove an AutoGenerated column? I wnat to inlcude the primary key in the resultset for creating some custom LinkButtons, but I don't want it (the PK) displayed in the DataGrid. I tried...
11
14981
by: Jo | last post by:
Hi all, I have a gridview displaying a dataset and some buttons. When a certain cell of this datasetrow is empty, I want a button in that row to be visible, otherwise no button should be shown...
2
2000
by: joe | last post by:
how to access invisible column inside gridview
5
3981
by: bbawa1 | last post by:
I have a GetData methd which is returning a table using
2
3034
by: Mariano | last post by:
Greetings, pls help me friends...somebody knows how could I see the value of a cell belong to invisible column in gridview? I have a table with fields like that : name, last name, address. I show...
9
4774
by: Mel | last post by:
I have 10 columns total. 3 of them are invisible. The rest are read- only BoundFields, 3 of which are editable fields using TemplateFields. Upon editing, I want to validate what the user enters...
0
4998
by: =?Utf-8?B?SlA=?= | last post by:
I have several data sources that use the same gridView. I need to remove columns from the gridview at run time where the DataBind.Eval statements dont apply to the query currently using the grid. ...
0
7118
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
7157
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,...
1
6862
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
7364
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...
0
4579
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
3087
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...
0
1397
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 ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
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...

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.