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">

    <asp:GridView ID="gvWorkActivitySelections" runat="server" AutoGenerateColumns="False"
        EnableModelValidation="True" OnRowCommand="ChoicesUpdate" 
            <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" />

More Info


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s