Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > hiding a column

Reply
Thread Tools

hiding a column

 
 
Guest
Posts: n/a
 
      06-17-2005
Hi
Where is the proper place to hide a column dynamically? I tried putting
this line in ItemDataBound,

myDataGrid.Columns[2].Visible = false;

but is giving me index out of range error! Am I putting this in a wrong
place (ItemDataBound)?

Any idea?
TIA

--



 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      06-17-2005
Well, I fixed the problem. We can not have AutoGenerateColumns="true", if
you want to set Column Visible property in ItemDataBound / Page_Load !!?

Can we have the AutoGenerateColumns="true", and still be able to set Column
Visible property elsewhere?
Anyone knows?

<dl> wrote in message news:%(E-Mail Removed)...
> Hi
> Where is the proper place to hide a column dynamically? I tried putting
> this line in ItemDataBound,
>
> myDataGrid.Columns[2].Visible = false;
>
> but is giving me index out of range error! Am I putting this in a wrong
> place (ItemDataBound)?
>
> Any idea?
> TIA
>
> --
>
>
>



 
Reply With Quote
 
 
 
 
Kim Quigley
Guest
Posts: n/a
 
      06-17-2005
I tried setting AutoGenerateColumns to true and then changing column
visibility in the code behind but the column count is always 0. I can think
of 3 ways to get around this:

1-Don't use AutoGenerateColumns
2-Modify the select statement so that only certain columns are returned, if
binding to a database.
3-Create all of the columns programmatically.

Is there a reason that you have to use AutoGenerateColumns?

<dl> wrote in message news:(E-Mail Removed)...
> Well, I fixed the problem. We can not have AutoGenerateColumns="true", if
> you want to set Column Visible property in ItemDataBound / Page_Load !!?
>
> Can we have the AutoGenerateColumns="true", and still be able to set
> Column
> Visible property elsewhere?
> Anyone knows?
>
> <dl> wrote in message news:%(E-Mail Removed)...
>> Hi
>> Where is the proper place to hide a column dynamically? I tried putting
>> this line in ItemDataBound,
>>
>> myDataGrid.Columns[2].Visible = false;
>>
>> but is giving me index out of range error! Am I putting this in a wrong
>> place (ItemDataBound)?
>>
>> Any idea?
>> TIA
>>
>> --
>>
>>
>>

>
>



 
Reply With Quote
 
Saladin
Guest
Posts: n/a
 
      06-18-2005
try this (from datagridgirl.com)

Question: How do I hide a column in my Datagrid if AutoGenerateColumns 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.Columns(1).Visible = False

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

<aspataGrid id="Datagrid1" runat="server" AutoGenerateColumns="True"
OnItemDataBound="Datagrid1_OnItemDataBound"/>

Private Sub DataGrid1_ItemDataBound(s As Object, e As DatagridItemEventArgs)
e.Item.Cells(1).Visible = False
End Sub

Graeme

<dl> wrote in message news:%(E-Mail Removed)...
> Hi
> Where is the proper place to hide a column dynamically? I tried putting
> this line in ItemDataBound,
>
> myDataGrid.Columns[2].Visible = false;
>
> but is giving me index out of range error! Am I putting this in a wrong
> place (ItemDataBound)?
>
> Any idea?
> TIA
>
> --
>
>
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      06-19-2005
Yes, you can have AutoGenerateColumns="true" and set columns properties in
ItemCreated event.

Eliyahu

<dl> wrote in message news:(E-Mail Removed)...
> Well, I fixed the problem. We can not have AutoGenerateColumns="true", if
> you want to set Column Visible property in ItemDataBound / Page_Load !!?
>
> Can we have the AutoGenerateColumns="true", and still be able to set

Column
> Visible property elsewhere?
> Anyone knows?
>
> <dl> wrote in message news:%(E-Mail Removed)...
> > Hi
> > Where is the proper place to hide a column dynamically? I tried putting
> > this line in ItemDataBound,
> >
> > myDataGrid.Columns[2].Visible = false;
> >
> > but is giving me index out of range error! Am I putting this in a wrong
> > place (ItemDataBound)?
> >
> > Any idea?
> > TIA
> >
> > --
> >
> >
> >

>
>



 
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
Script for Hiding/Un-Hiding Text On Click Ste Javascript 41 08-01-2007 02:35 PM
Hiding a hyperlink in a non-databound datagrid column BobRoyAce ASP .Net 2 01-20-2005 04:24 PM
DataGrid - Hiding a Column - Not Working David Freeman ASP .Net 7 10-25-2004 07:01 AM
dynamic hiding/showing of template column beccak ASP .Net 4 06-09-2004 01:44 AM
hiding a column of datagrid: dataset chosen at run-time Michelle Stone ASP .Net 0 10-15-2003 10:01 AM



Advertisments