gridview hide column, passing value hidden

I have a gridview with binded with a datatable. I have 4 fields in grid. Id, name, price and a button column. I need to know the value of the id when i press the button. If show the id column all works well. But i need hide the id column, and when hide this column an error occurs. How can pass a value in a hidden column in a gridview.
Who is Participating?
M3mph15Connect With a Mentor Commented:

You can hide the Column by using a CssClass:

.HiddenColumn 'in style section of <head>

<asp:BoundField DataField="Action_Key"  HeaderText="Key" InsertVisible="False" >
               <HeaderStyle CssClass="HiddenColumn" />
               <ItemStyle CssClass="HiddenColumn" />

Just change the Asp:BoundField to whatever suits your needs....the important bit is the HeaderStyle and ItemStyle.

Then in you can access the value from code behind with no problem.

ki_kiConnect With a Mentor Commented:
you can use css file to hide the column too.
if you have the footer's show property set to true, you'll have to 'style' it as well.
Am I right M3mph15 ?
Ah yes you can use the same method to hide the footer aswell
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.