Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to integrate paypal's shopping cart into my site. To do this all i need to do is add an additem button for each item i intend to sell. If my site was coded in html, i would just paste the bellow code per each item :

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">

<input type="hidden" name="add" value="1">

<input type="hidden" name="cmd" value="_cart">

<input type="hidden" name="business" value="name@business.com">

<input type="hidden" name="item_name" value="toycar">

<input type="hidden" name="item_number" value="c90">

<input type="hidden" name="amount" value="3.00">

<input type="hidden" name="no_note" value="1">

<input type="hidden" name="currency_code" value="USD">

<input type="hidden" name="bn" value="PP-ShopCartBF">

</form>

 

(the above creates an additem button for each item that when pressed it takes the user to the shopping cart hosted by paypal where they can see their items)

 

However im trying to acomplish the above in a more dynamic way by using a data grid, and changing the values of these items depending on the product selected by the user. In this way only one button is needed instead of one per item.

 

I have unsuccesfully tried placing the additem button on the ASP and have an onclick event handler method to take the posting action like so:

 
Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
       Dim URLString As String
       Dim postValues As String
       Dim byteArray As Byte()
       Dim myWebClient As New System.Net.WebClient
       Dim sendArray As Byte()

       URLString = "https://www.paypal.com/cgi-bin/webscr"

postValues= "add=1&cmd=_cart&business=name@business.com&item_name=" & txtNombP.Text & "&item_number=" & txtCodP.Text & "&amount=" & Textprice.Text & "&no_note=1&currency_code=USD&bn=PP-ShopCartBF"
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
 byteArray = System.Text.Encoding.ASCII.GetBytes(postValues)
 sendArray = myWebClient.UploadData(URLString, "POST", byteArray)
End Sub

The above code grabs the name and price of the product from the textboxes that are dynamically updated when a new product is selected from the datagrid, however i am doing something wrong since i cannot get to the paypal's shopping cart site whenever i press the button to additem to cart.

 

Any hints?

Posted

Using buttons in the datagrid is a lot tricker.

You need to use the datagrid's .ItemCommand event to handle buttons inside a datagrid.

 

Typically inside the datagrid, for each button in the column you need to create a Template Column Similar to this:

<asp:TemplateColumn HeaderText="Buy It">
    <ItemTemplate>
         <asp:Button id=btnBuyIt runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemKey") %>'   CommandName="PurchaseItem">Buy It</asp:Button>
    </ItemTemplate>
</asp:TemplateColumn>		

 

Then in the code behind. Have an event for the datagrid

       Private Sub dg_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand
           Try
               If e.CommandName = "PurchaseItem" Then 'PurchaseItem is the commandName from the above coding in the datagrid
                   'Pass the information to paypal based on e.CommandArgument (Which from the above datagrid is going to be the ItemKey) 
               End If
           Catch ex As Exception
               Throw ex
           End Try
       End Sub

 

That should at least get you started in the direction you are looking for.

 

I am trying to integrate paypal's shopping cart into my site. To do this all i need to do is add an additem button for each item i intend to sell. If my site was coded in html, i would just paste the bellow code per each item :

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">

<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">

<input type="hidden" name="add" value="1">

<input type="hidden" name="cmd" value="_cart">

<input type="hidden" name="business" value="name@business.com">

<input type="hidden" name="item_name" value="toycar">

<input type="hidden" name="item_number" value="c90">

<input type="hidden" name="amount" value="3.00">

<input type="hidden" name="no_note" value="1">

<input type="hidden" name="currency_code" value="USD">

<input type="hidden" name="bn" value="PP-ShopCartBF">

</form>

 

(the above creates an additem button for each item that when pressed it takes the user to the shopping cart hosted by paypal where they can see their items)

 

However im trying to acomplish the above in a more dynamic way by using a data grid, and changing the values of these items depending on the product selected by the user. In this way only one button is needed instead of one per item.

 

I have unsuccesfully tried placing the additem button on the ASP and have an onclick event handler method to take the posting action like so:

 
Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
       Dim URLString As String
       Dim postValues As String
       Dim byteArray As Byte()
       Dim myWebClient As New System.Net.WebClient
       Dim sendArray As Byte()

       URLString = "https://www.paypal.com/cgi-bin/webscr"

postValues= "add=1&cmd=_cart&business=name@business.com&item_name=" & txtNombP.Text & "&item_number=" & txtCodP.Text & "&amount=" & Textprice.Text & "&no_note=1&currency_code=USD&bn=PP-ShopCartBF"
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
 byteArray = System.Text.Encoding.ASCII.GetBytes(postValues)
 sendArray = myWebClient.UploadData(URLString, "POST", byteArray)
End Sub

The above code grabs the name and price of the product from the textboxes that are dynamically updated when a new product is selected from the datagrid, however i am doing something wrong since i cannot get to the paypal's shopping cart site whenever i press the button to additem to cart.

 

Any hints?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...