asp.net VB gridview value from a hidden column

I am uing a gridview to display a list of orders, and when the user clicks on the selected order header the detail comes up. I am using the Id from the order header to get the order detail.

This works fine and the code behind is:-

 Private Sub GridView1_SelectedIndexChanged
        Try
            StockPotrnId = GridView1.SelectedRow.Cells(2).Text
        Catch ex As Exception

        End Try
        Session("CurrentDate") = Calendar1.SelectedDate
        Session("StockPotrnId") = StockPotrnId
        Response.Redirect("frmstockorderdetail.aspx?StockPotrnId=" + StockPotrnId.ToString())
    End Sub

Now the grid is getting full and I would like to hide the cell containing the Id to give me more room, but if I hide the cell this doesn't work. Is there any way round this?
grwallaceAsked:
Who is Participating?
 
Obadiah ChristopherConnect With a Mentor Commented:
Alternatively you could try the GridView Datakey approach

DataKeys
0
 
CodeCruiserCommented:
Instead of using Visible=false, use style="display:none" which will make the column render but stay hidden so you can still access it.
0
 
grwallaceAuthor Commented:
The Gridview Datakey approach does work, but I can't get the style="Display:none" approach.
The code for the column is:-

 <asp:BoundField DataField="PoTrnId" HeaderText="PoTrnId" InsertVisible="False"
            ReadOnly="True" SortExpression="PoTrnId"  itemstyle-width="3em"   >
<ItemStyle Width="3em"  ></ItemStyle>
        </asp:BoundField>

Exactly where should I insert this to get it to work? The reason I ask is that while the primary key is exactly what I am looking for in this example, on the next page it is not, and if I can get the Style option to work that would do the trick in the next example
0
 
Obadiah ChristopherConnect With a Mentor Commented:
It has to be done in GridView Row DataBound event.

if(e.Row.RowType == DataControlRowType.DataRow
e.Row.Cells[2].Styles.Add("display","none");

Open in new window

0
 
CodeCruiserConnect With a Mentor Commented:
I think its the ControlStyle property for the boundfield

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datacontrolfield.controlstyle.aspx

if that does not work, then try converting it into template column.
0
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.