6

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sujeesh
  • 488
  • 2
  • 7
  • 15

1 Answers1

11

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?

Edit 1

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.

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • I have 3 boundfields. I need one more column to store hidden values. – sujeesh Feb 11 '13 at 10:13
  • can you put the html of your gridview – शेखर Feb 11 '13 at 10:17
  • But I need a column invisible to user but accessible using JavaScript. Because I need to set column1 color according to the value of Column2. But Column2 should no see by user. – sujeesh Feb 11 '13 at 10:31
  • @sujeesh what I am saying that convert one of your bound field in a template filed and in the same column add a hidden field. Can you put your .cs page and html? – शेखर Feb 11 '13 at 10:36