• 0

[VB, ASP.NET 2.0] How to Pass Values from One Gridview to Another


Question

I am designing a shopping basket site and have a gridview on one page displaying a list of products from a database. The gridview has a column where the user can specify the quantity of the item they wish to purchase and then a button next to it with will allow them to add it to their basket. At the moment when the user select the add basket it displays the number entered in the quantity cell in a message box, as shown below.

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand

Dim TextBox As TextBox
TextBox = GridView1.Rows(e.CommandArgument).Cells(5).Controls.Item(0)
MsgBox(TextBox.Text)

End Sub

I have also previously created a message box to show the item number of the product for which they selected the add to basket button for.

What I am trying to achieve is for the user to select multiple items like this and then allow them to view their basket on another page. When the user goes to this page I would like the values to be passed to a gridview on the page and displayed.

How would I go about passing values like this? Any examples would be very welcome.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Typically, have a column of checkboxes down the left column. Collect the corresponding row data needed for each checkbox and pass it over. If you need code example, let me know.

Link to comment
Share on other sites

  • 0

What Rohdekill suggested is a very good idea. To add on to that, if you use Rohdekill's method of using a CheckBox, add every item that has a CheckBox "checked" to an array, then put that array into a session variable. When you go to the next page, check to see if the session variable is null or in this case, Nothing, and if it's not "Nothing", assign the values in the array to the GridView.

Link to comment
Share on other sites

  • 0

I do it slightly differently, but basically the same...

I add only checked boxes directly to the session (i.e. "14,22,23,30"). When passed, simply say dim boxarray() =split(session("boxes"),",").

Link to comment
Share on other sites

  • 0

Yeah, that'd work too, I guess whatever is easiest or whichever way you feel more comfortable using.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.