Insert hidden column in asp:GridView but still available client side
-
28-09-2019 - |
Question
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?
Solution
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>
OTHER TIPS
Item attribute
ItemStyle-CssClass="hidden"
css class
.hidden{ display: none; }
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
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow