m.edmondson
m.edmondson

Reputation: 30872

Insert hidden column in asp:GridView but still available client side

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

Answers (4)

Tim B James
Tim B James

Reputation: 20364

Item attribute

ItemStyle-CssClass="hidden"

css class

.hidden{ display: none; }

Upvotes: 3

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

M4N
M4N

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

user151323
user151323

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

Related Questions