4

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?

m.edmondson
  • 30,382
  • 27
  • 123
  • 206

4 Answers4

10

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>
M4N
  • 94,805
  • 45
  • 217
  • 260
3

Item attribute

ItemStyle-CssClass="hidden"

css class

.hidden{ display: none; }
Nalaka526
  • 11,278
  • 21
  • 82
  • 116
Tim B James
  • 20,084
  • 4
  • 73
  • 103
2

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
j_freyre
  • 4,623
  • 2
  • 30
  • 47
1

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.

  • Don't worry theres nothing secure in here. So where do I apply this style? Item template? This was my initial reaction also but I couldn't get it to take effect. – m.edmondson Oct 08 '10 at 10:25