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

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

how to pass datagrid value from one page to another page

Hi,

I have a datagrid in one page. I want to pass the first column's value from this page to the next page. Do I need to use session variables and loop through the grid?

thanks a lot

k

0
kate_y
Asked:
kate_y
  • 6
  • 3
1 Solution
 
b1xml2Commented:
there are a few ways to go about it.
to get the first column's values, assuming the DataGrid is named DataGrid1

Dim value As String = DataGrid1.Items(0).Cells(0).Text


Page1
====
Response.Redirect("page2.aspx?Param=" & value,True)

Page2
====
'you just call this property to get the value
ReadOnly Property Param() As String
      Get
            Dim value As String = String.Empty
            If Not Request.QueryString("Param") Is Nothing Then
                  value = Request.QueryString("Param")
            End If
            Return value
      End Get
End Property


0
 
b1xml2Commented:
Page 1
====
Session("Param") = value
Response.Redirect("page2.aspx",True)

Page 2
=====
ReadOnly Property Param() As String
     Get
          Dim value As String = String.Empty
          If Not Session("Param") Is Nothing Then
               value = Session("Param").ToString
          End If
          Return value
     End Get
End Property
0
 
b1xml2Commented:
The property in page 2 allows you to retrieve it when you want to rather than having to worry about getting it and parking it into some other variable.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kate_yAuthor Commented:
Thanks for the quick response. It is great! I have two questions though.

1. Do i have to use a button to trigger this code? Can i use hyperlink instead of button?

2. What if i want the next page to show up at the right frame? Does response.redirect open up a new window?

thanks
0
 
b1xml2Commented:
You can use the LinkButton instead of a Button. It will be outputted as an anchor tag(<a>) but will perform a postback

<asp:LinkButton Id="NextPageLink" runat="server" OnClick="NextPageLink_Click">Next</asp:LinkButton>


Sub NextPageLink_Click(ByVal sender As Object,ByVal e As EventArgs)
   'your code to move to next page.
End Sub
0
 
kate_yAuthor Commented:
Does response.redirect open up a new window? Can the next page show in the right frame? does linkbutton have target property? i know when use hyperlink to, we can se t the target = "right frame" to open the next page in a frame. How to use button or linkbutton to do that?

thanks
0
 
b1xml2Commented:
Sub NextPageLink_Click(ByVal sender As Object,ByVal e As EventArgs)
   'your code to move to next page.
   Dim value As String = DataGrid1.Items(0).Cells(0).Text
   Dim url As String = "page2.aspx?Param=" & value
   Dim frame As String = "right" 'whatever it is named
   Page.RegisterClientScriptBlock("move","<script>window.onload = function() { window.frames['" & frame & "'].location.href = '" & url & "';};</script>")
End Sub

or

Sub NextPageLink_Click(ByVal sender As Object,ByVal e As EventArgs)
   'your code to move to next page.
   Session("Param") = DataGrid1.Items(0).Cells(0).Text
   Dim url As String = "page2.aspx"
   Dim frame As String = "right" 'whatever it is named
   Page.RegisterClientScriptBlock("move","<script>window.onload = function() { window.frames['" & frame & "'].location.href = '" & url & "';};</script>")
End Sub
0
 
kate_yAuthor Commented:
thank you so much.
0
 
b1xml2Commented:
=)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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