How To Render Column Data In GridView But Hide It From The User

There may be a time where you want to hide a GridView Column from a user but still need to access the data bound to the particular column.

Use CSS and apply it to the BoundField’s ItemStyle:

<style type="text/css">
    .hiddencol
    {
        display:none;
    }

</style>
    <asp:GridView ID="gvWorkActivitySelections" runat="server" AutoGenerateColumns="False"
        EnableModelValidation="True" OnRowCommand="ChoicesUpdate" 
        ShowHeader="False">
        <Columns>
            <asp:ButtonField ButtonType="Button" Text="Remove" CommandName="remove" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" >           
            <ItemStyle CssClass="hiddencol" />
            </asp:BoundField>
            
            
        </Columns>
    </asp:GridView>

More Info

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s