Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to remove/make invisible autogenerated gridview column

Reply
Thread Tools

How to remove/make invisible autogenerated gridview column

 
 
Julia B
Guest
Posts: n/a
 
      10-02-2008
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
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      10-02-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Julia B
Guest
Posts: n/a
 
      10-02-2008
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Making 1 control invisible while showing another in the exact location of the invisible one Andy B ASP .Net 5 05-29-2008 03:08 AM
Invisible - Succinic acid : (AMBER ACID) Invisible krithika.143@gmail.com C++ 0 04-14-2008 06:59 PM
Remove AutoGenerated DataGrid Column?? =?Utf-8?B?U3RldmU=?= ASP .Net 9 12-17-2005 02:35 AM
How to hide column in autogenerated DataGRID ?!?!?! jax ASP .Net 2 04-02-2004 02:56 AM



Advertisments