Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a column with hidden field in gridview

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.

like image 446
sujeesh Avatar asked Feb 11 '13 10:02

sujeesh


People also ask

How to make column hidden in GridView?

To hide a column programmaticallySet the DataGridViewColumn. Visible property to false .

How to add hidden field in GridView in ASP net?

The database columns can be hidden by binding it to DataKeyNames (DataKeys) property of the ASP.Net GridView. What are DataKeyNames and DataKeys? DataKeyNames is the property of GridView which allows us to set the names of the Column Fields that we want to use in code but do not want to display it.


1 Answers

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.

like image 141
शेखर Avatar answered Sep 21 '22 12:09

शेखर