Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 30, 2012 08:01 PM by lesponce
Member
108 Points
313 Posts
Apr 30, 2012 05:31 PM|LINK
I got a gridview with a BoundField set to Visible=False. The problem is that I need the value in the code behind.
How can I have that field invisible to the user, but visible in the code behind?
All-Star
32980 Points
8503 Posts
Moderator
Apr 30, 2012 05:55 PM|LINK
I think if you set the visibility of the column to false, it won't render the column, however you could use styling to hide the column itself using CSS.
Take a look at this article; http://www.codeproject.com/Tips/80964/How-to-get-Hidden-Column-Value-in-GridView
Star
10672 Points
2426 Posts
Apr 30, 2012 05:59 PM|LINK
In select command select that field also and add it to DataKeynames list and retrieve it whenever needed
If it is in RowdataBoundEvent get it as
string myKey = GridView1.DataKeys[e.RowIndex].Values[index of DatakeyNames].ToString();
Apr 30, 2012 06:25 PM|LINK
It's in a RowCommand event because of a Select Button.
Apr 30, 2012 06:30 PM|LINK
OnRowDataBound should still work even if its a rowcommand.
Apr 30, 2012 08:01 PM|LINK
I ended up using this one.... Thx for your help.
// Bind GridView to Data Source GVAddress.DataSource = dtAddress; GVAddress.DataBind();
//Set visible to false for AddressId column after binding
(Step 4) from your link
lesponce
Member
108 Points
313 Posts
Gridview Hidden Field but Visible in the Code Behind
Apr 30, 2012 05:31 PM|LINK
I got a gridview with a BoundField set to Visible=False. The problem is that I need the value in the code behind.
How can I have that field invisible to the user, but visible in the code behind?
bbcompent1
All-Star
32980 Points
8503 Posts
Moderator
Re: Gridview Hidden Field but Visible in the Code Behind
Apr 30, 2012 05:55 PM|LINK
I think if you set the visibility of the column to false, it won't render the column, however you could use styling to hide the column itself using CSS.
Take a look at this article; http://www.codeproject.com/Tips/80964/How-to-get-Hidden-Column-Value-in-GridView
basheerkal
Star
10672 Points
2426 Posts
Re: Gridview Hidden Field but Visible in the Code Behind
Apr 30, 2012 05:59 PM|LINK
In select command select that field also and add it to DataKeynames list and retrieve it whenever needed
If it is in RowdataBoundEvent get it as
(Talk less..Work more)
lesponce
Member
108 Points
313 Posts
Re: Gridview Hidden Field but Visible in the Code Behind
Apr 30, 2012 06:25 PM|LINK
It's in a RowCommand event because of a Select Button.
bbcompent1
All-Star
32980 Points
8503 Posts
Moderator
Re: Gridview Hidden Field but Visible in the Code Behind
Apr 30, 2012 06:30 PM|LINK
OnRowDataBound should still work even if its a rowcommand.
lesponce
Member
108 Points
313 Posts
Re: Gridview Hidden Field but Visible in the Code Behind
Apr 30, 2012 08:01 PM|LINK
I ended up using this one.... Thx for your help.
// Bind GridView to Data Source GVAddress.DataSource = dtAddress; GVAddress.DataBind();
//Set visible to false for AddressId column after binding
(Step 4) from your link