Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a button which is to send all items that has been added into the grid view into the pay pal site. Currently, it only send the first column of item into the paypal site. For example, I have item A and item B in the shopping cart. Only item A information will go to the paypal site while not item B. Please help me. Thanks and Best regards!:D

Grid view code:
<asp:GridView ID="gv_CartProduct" runat="server" AutoGenerateColumns="False" onRowCommand="gv_CartProduct_OnRowCommand">
           <asp:TemplateField HeaderText="Title">
                   <asp:Label ID="lbl_title" Text='<%# Eval("title") %>' runat="server"></asp:Label>
              <asp:TemplateField HeaderText="Image">
                           <asp:Image ID="imgPreview" ImageUrl='<%# Eval("image")  %>' runat="server"
                               Height="80px" Width="80px" />

           <asp:BoundField DataField="price" HeaderText="Price" DataFormatString="{0:0.00}" />
          <asp:TemplateField HeaderText="Quantity">
               <asp:TextBox ID="tb_quantity" runat="server"  CommandArgument='<%# Eval("title")%>' Text='<%# Eval("qty") %>' ></asp:TextBox>
           <asp:LinkButton ID="btn_delete" runat="server" Text="Delete" CommandName="deleterow" CommandArgument='<%# Eval("title") %>' OnClientClick="return confirm('Do you want to delete product?');"  ></asp:LinkButton>

Button code(Checkout to paypal):
<asp:Button ID="btn_Checkout" runat="server" OnClick="btn_Checkout_Click" Text="Checkout" />

btn_checkout_Click code:
protected void btn_Checkout_Click(object sender, EventArgs e)
           CartBLL cbll = new CartBLL();
           Cart c1 = new Cart();
           username = (string)(Session["username"]);

           foreach (GridViewRow row in gv_CartProduct.Rows)
               if (row.RowType == DataControlRowType.DataRow)

                   string qtystring = ((TextBox)(row.FindControl("tb_quantity"))).Text;
                   string title = ((Label)row.FindControl("lbl_title")).Text;
                   int amount = Convert.ToInt32(row.Cells[2].Text);
                   string amountInString = amount.ToString();

                   string redirectUrl = "";

                   //Mention URL to redirect content to paypal site
                   redirectUrl += "" + ConfigurationManager.AppSettings["paypalemail"].ToString();

                   //First name I assign static based on login details assign this value
                   redirectUrl += "&first_name=" + username;

                   //Product Name
                   redirectUrl += "&item_name=" + title;

                   redirectUrl += "&quantity=" + qtystring;

                   //Business contact paypal EmailID
                   redirectUrl += "&";

                   //price if any, or available or using shopping cart system
                   redirectUrl += "&amount=" + amount;

                           //If transactioin has been successfully performed, redirect SuccessURL page- this page will be designed by developer
               redirectUrl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();

               //If transactioin has been failed, redirect FailedURL page- this page will be designed by developer
               redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900