[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

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?
0
grwallace
Asked:
grwallace
  • 2
  • 2
3 Solutions
 
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
 
informaniacCommented:
Alternatively you could try the GridView Datakey approach

DataKeys
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
 
informaniacCommented:
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
 
CodeCruiserCommented:
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now