Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre lang="vb">
How do I create a shopping basket using asp.net 2010 vb. I have created a grid view of products and a click to the add to basket button is not bringing the results to the basket.

[edit]SHOUTING removed - OriginalGriff[/edit]

This is what I have. Whats the way forward?

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Advertise.aspx.vb" Inherits="Advertise" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style14
{
width: 150px;
}
.style15
{
width: 150px;
height: 26px;
}
.style16
{
height: 26px;
}
.style17
{
font-size: large;
}
</style>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server" ViewStateMode="Enabled">

Product Name <asp:TextBox ID="TextBoxProductName" runat="server">
     
<asp:Button ID="ButtonSearch" runat="server" Text="Search" />
   


 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="ProductID" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None">
<alternatingrowstyle backcolor="White">
<columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
SortExpression="ProductName" />
<asp:BoundField DataField="Decsription" HeaderText="Decsription"
SortExpression="Decsription" />
<asp:BoundField DataField="Category" HeaderText="Category"
SortExpression="Category" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:ButtonField CommandName="AddToBasket" Text="Add To Basket" />
<editrowstyle backcolor="#2461BF">
<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center">
<rowstyle backcolor="#EFF3FB">
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333"
BorderStyle="Solid" />
<sortedascendingcellstyle backcolor="#F5F7FB">
<sortedascendingheaderstyle backcolor="#6D95E1">
<sorteddescendingcellstyle backcolor="#E9EBEF">
<sorteddescendingheaderstyle backcolor="#4870BE">

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>"
SelectCommand="SELECT DISTINCT * FROM [Product] WHERE ([ProductName] LIKE '%' + @ProductName + '%')">
<SelectParameters>
<asp:ControlParameter ControlID="TextBoxProductName" Name="ProductName"
PropertyName="Text" Type="String" />
</SelectParameters>




<asp:View ID="ViewBasket" runat="server" ViewStateMode="Enabled">
Basket<asp:GridView ID="GridViewBasket"
runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" CellPadding="4" ClientIDMode="AutoID"
DataKeyNames="ProductID" ForeColor="#333333"
GridLines="Horizontal" EnablePersistedSelection="True" PageIndex="1">
<alternatingrowstyle backcolor="White">
<columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True"
SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName"
ReadOnly="True" SortExpression="ProductName" />
<asp:TemplateField HeaderText="Quantity">
<itemtemplate>
<asp:TextBox ID="TextBoxQuantity" runat="server">
<asp:LinkButton ID="Remove" runat="server" CommandName="Remove">Remove


<asp:BoundField DataField="Price" DataFormatString="{0:c}" HeaderText="Price"
ReadOnly="True" />
<asp:BoundField DataField="TotalCost" DataFormatString="{0:c}"
HeaderText="Total Cost" />
<editrowstyle backcolor="#2461BF">
<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center">
<rowstyle backcolor="#EFF3FB">
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<sortedascendingcellstyle backcolor="#F5F7FB">
<sortedascendingheaderstyle backcolor="#6D95E1">
<sorteddescendingcellstyle backcolor="#E9EBEF">
<sorteddescendingheaderstyle backcolor="#4870BE">



Total Price<asp:Label ID="Label1" runat="server" Text="Label">

<asp:View ID="View3" runat="server">

<asp:View ID="View4" runat="server">

<asp:View ID="View5" runat="server">

<asp:View ID="View6" runat="server">




 

Posted
Updated 3-Apr-13 2:57am
v4
Comments
OriginalGriff 2-Apr-13 5:44am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Kenneth Haugland 2-Apr-13 5:49am    
A List (of products)? I cant really see the problem.
StianSandberg 3-Apr-13 8:23am    
please put SOME effort in formatting your code. It's not readable and I don't even try to help you bacause I can't read your code.. sorry...

You will need to keep adding products to a container. For instance, you can have an object in session with the product collection inside a class container or a list of products. Session here are important, so you can switch between pages and don't loose your container information.
There are other solutions where you can keep your data between pages (html pages are stateless, so you will need to have a strategy to keep the container between pages).

Check this article: Simple Shopping Cart[^]
 
Share this answer
 

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