I need to insert a column with hidden field in grid view.
The user should not know that one column is there.
I tried the following: created a css class width display:none;
and assigned ItemStyle-CssClass="MyCssClass"
.
But result is not satisfactory.
Inserted a template field
and in itemtemplate
I had given a asp:HiddenField
Both method shows an extra column hidden field.
There is no value since the fields are rendered as hidden fields but that column have width nearly 10 pixels (see this image http://www.tiikoni.com/tis/view/?id=c500726).
So the user feels an empty row is there.
I need to completely hide the column.
I cannot use template field
with visibility=false
, because I need to access its value from client side.
To hide a column programmaticallySet the DataGridViewColumn. Visible property to false .
The database columns can be hidden by binding it to DataKeyNames (DataKeys) property of the ASP.Net GridView. What are DataKeyNames and DataKeys? DataKeyNames is the property of GridView which allows us to set the names of the Column Fields that we want to use in code but do not want to display it.
You can keep the hidden field in your any column. And get it's value from anywhere you live.
Here is a good link to call value from the server side
access hidden field within gridview control to set a value in javascript?
Add a column as follows:
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl1" runat="server"
Value='<%# Eval("Name") %>' />
<asp:HiddenField ID="HiddenField1" runat="server"
Value='<%# Eval("BirthDate") %>' />
</ItemTemplate>
</asp:TemplateField>
And you can get the values of your hidden field easily.
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