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.
To hide a column programmaticallySet the DataGridViewColumn. Visible property to false .
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.
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.
<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); }
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With