Reputation: 30872
This is simple. All I want to do is insert a hidden column into an asp:Griview that I'll be able to access through javascript. Any pointers?
Upvotes: 4
Views: 14106
Reputation: 20364
Item attribute
ItemStyle-CssClass="hidden"
css class
.hidden{ display: none; }
Upvotes: 3
Reputation: 21
This is what I did. I created a hidden field inside a TemplateField
in the .aspx
page
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="ITEM_VAL" runat="server" Value='<%# Bind("ITEM_VAL") %>' />
</ItemTemplate>
</asp:TemplateField>
Then in the code behind file -
protected Sub gvHist_RowDataBound()
Dim val as Integer
Dim hiddenCol As HiddenField = e.Row.FindControl("ITEM_VAL")
val = Convert.ToInt32(hiddenCol.Value)
End Sub
Upvotes: 2
Reputation: 96551
You can hide a column by setting its CssClass property, e.g:
<style>
.hidden {display:none;}
</style>
...
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" ItemStyle-CssClass="hidden"
HeaderStyle-CssClass="hidden" />
<asp:BoundField DataField="Title" />
</Columns>
</asp:GridView>
Upvotes: 10
Reputation:
Add to it the CSS property display:none
. It will be unvisible but still present in the markup.
However this is not secure as the customer might unlock this column by using tools like FireBug which allows to override properties.
Upvotes: 1