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.
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.