Solved VB gridview value from a hidden column

Posted on 2012-08-16
Last Modified: 2012-08-16
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
            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?
Question by:grwallace
    LVL 83

    Expert Comment

    Instead of using Visible=false, use style="display:none" which will make the column render but stay hidden so you can still access it.
    LVL 20

    Accepted Solution

    Alternatively you could try the GridView Datakey approach


    Author Comment

    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>

    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
    LVL 20

    Assisted Solution

    It has to be done in GridView Row DataBound event.

    if(e.Row.RowType == DataControlRowType.DataRow

    Open in new window

    LVL 83

    Assisted Solution

    I think its the ControlStyle property for the boundfield

    if that does not work, then try converting it into template column.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now