Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a column (GridView) but still access its value?

I have a GridView with a DataSource (SQL Database). I want to hide a column, but still be able to access the value when I select the record. Can someone show me how to do this?

This is the column I want to hide and still want to access its value:

<asp:BoundField DataField="Outlook_ID" HeaderText="OutlookID" /> 

I tried everything to hide the column (property Visible="false"), but I can't access its value.

like image 352
Tassisto Avatar asked Mar 21 '11 10:03

Tassisto


People also ask

How do I hide a column in grid view?

To hide a column programmaticallySet the DataGridViewColumn. Visible property to false .

How do you hide ASP BoundField?

You can do it by two ways. By hidden field it will easy to maintain to get value by name of hidden field instead of finding cell value in code. 1) Remove the BoundField of ID and add Hidenfield with value as Id which will use for File id on RowDataBound. So change in HTML and Code like below.

How do I hide the grid view?

GridView is an ASP.NET control, which means it will have a 'Visible' property, allowing you to show or hide the control itself. GridView. Visible = false; will prevent the control from being rendered at all.


2 Answers

<head runat="server"> <title>Accessing GridView Hidden Column value </title> <style type="text/css">   .hiddencol   {     display: none;   } </style>  <asp:BoundField HeaderText="Email ID" DataField="EmailId" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" > </asp:BoundField>  ArrayList EmailList = new ArrayList(); foreach (GridViewRow itemrow in gvEmployeeDetails.Rows) {   EmailList.Add(itemrow.Cells[YourIndex].Text); } 
like image 193
Mubashir Ahmed Avatar answered Oct 23 '22 11:10

Mubashir Ahmed


If I am not mistaken, GridView does not hold the values of BoundColumns that have the attribute visible="false". Two things you may do here, one (as explained in the answer from V4Vendetta) to use Datakeys. Or you can change your BoundColumn to a TemplateField. And in the ItemTemplate, add a control like Label, make its visibility false and give your value to that Label.

like image 23
serhat_bundy Avatar answered Oct 23 '22 11:10

serhat_bundy