Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Hide a column in asp:GridView

 
Thread Tools Search this Thread
Old 08-04-2006, 08:28 AM   #1
Default Hide a column in asp:GridView


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 <div> inside for setting it
display:none. What can I do? Thanks in millions.




ghostwolf
  Reply With Quote
Old 08-04-2006, 09:47 AM   #2
=?Utf-8?B?Y2xpY2tvbg==?=
 
Posts: n/a
Default RE: Hide a column in asp:GridView

To hide the third column for example ...

GridView.Columns[2].Visible = false;

"ghostwolf" wrote:

> 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 <div> inside for setting it
> display:none. What can I do? Thanks in millions.
>
>
>

  Reply With Quote
Old 08-04-2006, 10:06 AM   #3
Mark Rae
 
Posts: n/a
Default Re: Hide a column in asp:GridView

"ghostwolf" <> wrote in message
news:...

> 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 <div> inside for setting it
> display:none. What can I do? Thanks in millions.


MyGridView.Columns[0].Visible = false;

HOWEVER, bear in mind that this isn't actually *hiding* the column per se -
it's physically *removing* the column from the HTML being sent down to the
client, which may not be what you really want...


  Reply With Quote
Old 08-04-2006, 10:13 AM   #4
ghostwolf
 
Posts: n/a
Default Re: Hide a column in asp:GridView

thanks, actually I don't really want to invisible it. It is because I want
to put a value for each row but make it hide away. Just like what we did in
windows programming for adding a value for each row. If I make the column in
asp:GridView invisible, I cannot get the value from that column.

"Mark Rae" <> wrote in message
news:...
> "ghostwolf" <> wrote in message
> news:...
>
>> 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 <div> inside for setting it
>> display:none. What can I do? Thanks in millions.

>
> MyGridView.Columns[0].Visible = false;
>
> HOWEVER, bear in mind that this isn't actually *hiding* the column per
> se - it's physically *removing* the column from the HTML being sent down
> to the client, which may not be what you really want...
>



  Reply With Quote
Old 08-04-2006, 11:09 AM   #5
Mark Rae
 
Posts: n/a
Default Re: Hide a column in asp:GridView

"ghostwolf" <> wrote in message
news:O4v$...

> thanks, actually I don't really want to invisible it. It is because I want
> to put a value for each row but make it hide away. Just like what we did
> in windows programming for adding a value for each row. If I make the
> column in asp:GridView invisible, I cannot get the value from that column.


Ah... You've discovered the additional security feature that a GridView has
but a DataGrid didn't.

Basically, Microsoft took the view that using hidden columns to store data
was a potential security risk, so they removed hidden colums from ViewState
at databind time. However, it's easy enough to work round, but be aware of
the potential security risk involved in doing this...

MyGridView.DataSource = <datasource>;
MyGridView.Columns[0].Visible = true;
MyGridView.DataBind();
MyGridView.Columns[0].Visible = false;


  Reply With Quote
Old 08-04-2006, 03:13 PM   #6
Winista
 
Posts: n/a
Default Re: Hide a column in asp:GridView

Check this out..

http://www.netomatix.com/development...ideColumn.aspx

"ghostwolf" <> wrote in message
news:...
> 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 <div> inside for setting it
> display:none. What can I do? Thanks in millions.
>



  Reply With Quote
Old 08-04-2006, 03:37 PM   #7
Mark Rae
 
Posts: n/a
Default Re: Hide a column in asp:GridView

"Winista" <> wrote in message
news:...

> Check this out..
>
> http://www.netomatix.com/development...ideColumn.aspx


Correct approach, terrible implementation!

Need to set display to either none or block to make this work properly.


  Reply With Quote
Old 08-04-2006, 04:04 PM   #8
Winista
 
Posts: n/a
Default Re: Hide a column in asp:GridView

Thank you for pointing out the issue with the approach. It has been fixed on
the site as well as attached demo project.

"Mark Rae" <> wrote in message
news:...
> "Winista" <> wrote in message
> news:...
>
>> Check this out..
>>
>> http://www.netomatix.com/development...ideColumn.aspx

>
> Correct approach, terrible implementation!
>
> Need to set display to either none or block to make this work properly.
>



  Reply With Quote
Old 08-04-2006, 04:15 PM   #9
Mark Rae
 
Posts: n/a
Default Re: Hide a column in asp:GridView

"Winista" <> wrote in message
news:u$WE8%...

> Thank you for pointing out the issue with the approach. It has been fixed
> on the site as well as attached demo project.


Excellent. Check this out for cross-browser compatibility
http://www.quirksmode.org/css/display.html, but I think you're OK...


  Reply With Quote
Old 08-06-2006, 11:19 PM   #10
ghostwolf
 
Posts: n/a
Default Re: Hide a column in asp:GridView

Thanks, it's great for me.

"Mark Rae" <> wrote in message
news:umI5vD%...
> "Winista" <> wrote in message
> news:u$WE8%...
>
>> Thank you for pointing out the issue with the approach. It has been fixed
>> on the site as well as attached demo project.

>
> Excellent. Check this out for cross-browser compatibility
> http://www.quirksmode.org/css/display.html, but I think you're OK...
>



  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump