Showing posts with label cart. Show all posts
Showing posts with label cart. Show all posts

Thursday, March 29, 2012

Session Variable

I'm using on my shopping cart a session variable to store all products that user have put in to the cart.
The script that I use is writen from a book that I bought. I managed to edit the script so that It suites me.
But I have a problem., The book don't tell how to do the checkoutfunction. How can I get all values from the session variable and storethem to my database.
Major problem is that I don't know how to do the for loop that shouldreed the session variable and give value to the parameters.
Session variable (cart) have following variables stored (cartid:integer, PID:integer , PAKID:Integer , Productname:String , Quantity:integer ,Price:Decimal)
Please Help me with this.
If you download the source code for the Commerce Starter Kit from the "Starter Kits" tab on this web site, it has a great example on how to handle storing items in a shopping cart, and then handling the checkout.
smtraber
It's prity big I'm not so good at coding. I have mostly of my time used Dreamweaver.


<%
For Each Cartid in Session("cart")
       Response.Write cartid & "=" & Session("cart") & "<br>"
Next
%>
Wuold this work to print the cartid in the session cart.
I have in the session following strings also: PID,PAKID,quantity all integer and price as decimal and productname as string
How should I insert the code into this for each loop so I would get value of all the variables in the session varibale

Monday, March 26, 2012

Session variable details

Good afternoon, I have two pages one is a select movie page the other is a view cart page, the problem is when i select a movie the details do not show up on the view cart page, can someone point me in the right direction please. below is my code;

select movie code;

<%

@dotnet.itags.org.PageLanguage="C#"Debug="true"AutoEventWireup="true"CodeFile="SelectedFilm.cs"Inherits="SelectedFilm "%>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"lang="en">

<

head>

<

metahttp-equiv="Content-Type"content="text/html; charset=iso-8859-1"/>

<

metaname="description"content="Description of your web page goes here."/>

<

metaname="keywords"content="Keywords for you web page go here. Each keyword or group of keyword phrases are separated by a comma. Keep this keyword list short and relevant to the content of this specific page and also relevant to the tile of the specific page."/>

<

title>Movie Stream</title>

<

linkrel="shortcut icon"href="shortcut.jpg"/>

<

linkhref="moviestream.css"rel="stylesheet"type="text/css"/>

<

scriptlanguage="javascript"type="text/javascript">

</

script>

</

head>

<

bodystyle="background-color: #dcdcdc"><formid="form1"runat="server">

<

divid="mainnav-container"><divid="mainnav"><divclass="none"><ahref="#maincontent"></a> </div><ul><li><ahref="layout.aspx"title=""><spanstyle="font-size: 11pt">Home</span></a><spanstyle="font-size: 11pt"> </span></li><li><ahref="#"title=""><spanstyle="font-size: 11pt">Contact</span></a></li><li><ahref="MS_Admin.aspx"title=""><spanstyle="font-size: 11pt">Admin Login</span></a><spanstyle="font-size: 11pt">

<%

-- <li><a href="http://links.10026.com/?link=MS_Admin.aspx" title=""><span style="font-size: 11pt">Admin Login</span></a><span style="font-size: 11pt">

--

%></span></li></ul></div><divid="mainnav-side"><ul><li><ahref="registered_customer.aspx"title=""><spanstyle="font-size: 12pt">Login</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="new_customer.aspx"title=""><spanstyle="font-size: 12pt">Register</span></a></li></ul></div><divclass="clear"></div>

</

div>

<!--

SITE NAME & SLOGAN

-->

<

divid="header">

<

ahref="layout.aspx"title="Site name home page"></a><divid="slogan"><spanstyle="font-family: Trebuchet MS"><spanstyle="font-size: 12pt">

MOVIE STREAM

<br/></span>

"Delivering movies to your desk top"

</span></div>

</

div>

<

divid="breadcrumb-container"><divid="breadcrumb"><ahref="layout.aspx"title="Users will see this text ">Home</a> /<ahref="#"title="Users will see this text">Breadcrumb link</a> / Page Title</div><divid="breadcrumb-side">

Search <asp:TextBoxid="SearchWord"runat="server"></asp:TextBox> <asp:ButtonID="Button1"runat="server"Text="go"OnClick="Button1_onclick"/>

<%

-- <asp:Button /> id="Button1" type="button" value="Go" language="javascript" onclick="Button1_onclick()" />--%><asp:LabelID="lblMessage"runat="server"Text=""></asp:Label><br/> </div><divclass="clear"></div>

</

div>

<!--

CONTENT

-->

<

divid="content-container"style="background-color: #ffffff"><!--

SIDE COLUMN

-->

<divid="content-side"style="left: 1px"><p><spanstyle="font-size: 14pt; font-family: Trebuchet MS; color: gray;">Genre</span></p><ulclass="link-list-vertical"><li><ahref="MS_Action.aspx"title="Movies to give you an Adrenaline rush."><spanstyle="font-size: 12pt">

Action

</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="MS_Anime.aspx"title="Animated movies."><spanstyle="font-size: 12pt">Anime</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Movies to make you laugh."><spanstyle="font-size: 12pt">Comedy</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Strong following movies"><spanstyle="font-size: 12pt">Cult</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Facts or fiction."><spanstyle="font-size: 12pt">Documentary</span></a></li><li><spanstyle="font-size: 12pt"></span></li></ul></div><!--

MAIN COLUMN

-->

<divid="content"style="height: 1%"><aname="maincontent"id="maincontent"></a><h1><spanstyle="font-family: Trebuchet MS"></span></h1><br/><br/>

<asp:DataListID="DataList1"runat="server"DataSourceID="SqlDataSource1"OnSelectedIndexChanged="DataList1_SelectedIndexChanged1"><ItemTemplate>

Movie ID:

<asp:LabelID="Movie_IDLabel"runat="server"Text='<%# Eval("Movie_ID") %>'></asp:Label><br/><br/>

Genre Category:

<asp:LabelID="Genre_CategoryLabel"runat="server"Text='<%# Eval("Genre_Category") %>'></asp:Label><br/><br/>

Movie name:

<asp:LabelID="Movie_nameLabel"runat="server"Text='<%# Eval("Movie_name") %>'></asp:Label><br/><br/>

Release date:

<asp:LabelID="Release_dateLabel"runat="server"Text='<%# Eval("Release_date") %>'></asp:Label><br/><br/>

Length:

<asp:LabelID="LengthLabel"runat="server"Text='<%# Eval("Length") %>'></asp:Label><br/><br/>

Synopsis:

<asp:LabelID="SynopsisLabel"runat="server"Text='<%# Eval("Synopsis") %>'></asp:Label><br/><br/>

Starring:

<asp:LabelID="StarringLabel"runat="server"Text='<%# Eval("Starring") %>'></asp:Label><br/><br/>

Director:

<asp:LabelID="DirectorLabel"runat="server"Text='<%# Eval("Director") %>'></asp:Label><br/><br/>

Price:

<asp:LabelID="PriceLabel"runat="server"Text='<%# Eval("Price") %>'></asp:Label><br/><br/>

<asp:ButtonID="addToCartel"runat="server"OnClick="addToCart"Text="Select movie"/><br/></ItemTemplate></asp:DataList><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:movie_streamConnectionString5 %>"SelectCommand="SELECT [Movie_ID], [Genre_Category], [Movie_name], [Release_date], [Length], [Synopsis], [Starring], [Director], [Price] FROM [MS_Movies] WHERE ([Movie_name] = @dotnet.itags.org.Movie_name)"><SelectParameters><asp:QueryStringParameterDefaultValue="Movie_name"Name="Movie_name"QueryStringField="Movie_name"Type="String"/></SelectParameters></asp:SqlDataSource>

<!--

FOOTER

-->

<

divid="footer"><p>

Movie Stream

</p><p>

382 Brent Cross Road.

</p><p>

? 2007 Movie Stream. All rights reserved.

</p>

</

div></div><!--

SIDE 2 COLUMN

-->

<divid="content-side-2"><divclass="listbox"><divclass="header"><spanstyle="font-size: 12pt; font-family: Trebuchet MS; color: #dcdcdc;"><strongstyle="color: gray">New releases</strong></span></div><olclass="listbox"><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Deja Vu</span></b></a><spanstyle="font-family: Trebuchet MS"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Red Eye</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Dodgers</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Basketball diaries</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li></ol></div></div>

</

div>

</

form>

</

body>

</

html>

<%

-- <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="DataList1_SelectedIndexChanged1">

<ItemTemplate>

Movie ID:

<asp:Label ID="Movie_IDLabel" runat="server" Text='<%# Eval("Movie_ID") %>'></asp:Label><br />

<br />

Genre Category:

<asp:Label ID="Genre_CategoryLabel" runat="server" Text='<%# Eval("Genre_Category") %>'></asp:Label><br />

<br />

Movie name:

<asp:Label ID="Movie_nameLabel" runat="server" Text='<%# Eval("Movie_name") %>'></asp:Label><br />

<br />

Release date:

<asp:Label ID="Release_dateLabel" runat="server" Text='<%# Eval("Release_date") %>'></asp:Label><br />

<br />

Length:

<asp:Label ID="LengthLabel" runat="server" Text='<%# Eval("Length") %>'></asp:Label><br />

<br />

Synopsis:

<asp:Label ID="SynopsisLabel" runat="server" Text='<%# Eval("Synopsis") %>'></asp:Label><br />

<br />

Starring:

<asp:Label ID="StarringLabel" runat="server" Text='<%# Eval("Starring") %>'></asp:Label><br />

<br />

Director:

<asp:Label ID="DirectorLabel" runat="server" Text='<%# Eval("Director") %>'></asp:Label><br />

<br />

Price:

<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>'></asp:Label><br />

<br />

<asp:Button ID="addToCartie" runat="server" OnClick="addToCart" Text="Select movie" /><br />

</ItemTemplate>

</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:movie_streamConnectionString5 %>"

SelectCommand="SELECT [Movie_ID], [Genre_Category], [Movie_name], [Release_date], [Length], [Synopsis], [Starring], [Director], [Price] FROM [MS_Movies] WHERE ([Movie_name] = @dotnet.itags.org.Movie_name)">

<SelectParameters>

<asp:QueryStringParameter DefaultValue="Movie_name" Name="Movie_name" QueryStringField="Movie_name"

Type="String" />

</SelectParameters>

</asp:SqlDataSource>--

%>

selectfilm.cs code;

using

System;

using

System.Data;

using

System.Data.SqlClient;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclassSelectedFilm : System.Web.UI.Page

{

protectedvoid addToCart(object sender,EventArgs e)

{

if (IsPostBack)

{

Session[

"Movie_IDLabel"] = ("Movie_ID");

Session[

"Movie_nameLabel"] = ("Movie_name");

Session[

"Genre_CategoryLabel"] = ("Genre_Category");

Session[

"Movie_IDLabel"] = ("Movie_ID");

Session[

"Release_dateLabel"] = ("Release_date");

Session[

"LengthLabel"] = ("Length");

Session[

"SynopsisLabel"] = ("Synopsis");

Session[

"StarringLabel"] = ("Starring");

Session[

"DirectorLabel"] = ("Director");

Session[

"PriceLabel"] = ("Price");// Response.Redirect("viewcart.aspx");

}

Response.Redirect(

"viewcart.aspx");

}

And my view cart code;

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="viewcart.aspx.cs"Inherits="viewcart" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server">

<scriptlanguage="javascript"type="text/javascript">

</

script>

</

head>

<

body><formid="Form1"runat="server">

<asp:Labelid="Movie_IDLabel"runat="server"Font-size="30"></asp:Label><br/><br/><asp:Labelid="Movie_nameLabel"runat="server"Font-size="30"></asp:Label><br/><br/><asp:Labelid="PriceLabel"runat="server"Font-size="30"></asp:Label>

</form>

</

body>

</

html>

viewcart cs code

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

using

System.Web.Configuration;

using

System.Data.SqlClient;

using

System.Text.RegularExpressions;

public

partialclassviewcart : System.Web.UI.Page

{

void Page_Load(object sender,EventArgs e)

{

Movie_IDLabel.Text =

Convert.ToString(Session["Movie_ID"]);

Movie_nameLabel.Text =

Convert.ToString(Session["Movie_name"]);

PriceLabel.Text =

Convert.ToString(Session["Price"]);

}

Hi, I have not gone through all the code you have up there...but here is how you could do it..

On your first page set the session variables and access them on your second page...

I think you want to access the value of the textbox's or label's value in the second page rather than the name of them..

On first page...

Session["variable1"] = textBox1.value;

On the second page

string str = Session["variable1"];

Where as you are doing as the following..

Session["variable1"] = "Text" // where your text is the name of the control from what i see in the example you gave...


Hi thanks for your response, the problem is im trying to bring up a label and not a textbox, how would i go about doing this. thank you

Is there anyone out there who can help me please.


I believe you are saying that you want to get the "text value" of the label...

If thats right, you could do something like

Session["key1"] = label1.text; // this should be done on Page One

One second page, get the value from session as Session["key1"]

Saturday, March 24, 2012

Session variables

Hello!

I'm very new with ASP.NET so my question may be...

I'mworking in a webshop and I'm trying to build a shopping cart. Ihave made the products page with a datalist and a Access DB. My problemis when passing the item I chose to buy to the cart. I'm trying to usea session variable but don't know how send (cart.aspx?id=xx) and toreceive it.

Could someone try to explain that to me? Some examples would help too. (working with .NET 1.1 and VB).

Thanks in advance.

Store your id in a Session variable..

Session("ID") = some_value..

In your cart.aspx you can use

id = Cint(Session("ID"))

Don't forget to check if Session("ID") is Not Nothing in cart.aspx, otherwise it throws exceptions.


You can also take a look at this article to learn more about ASP.NET state management:

http://msdn2.microsoft.com/en-us/library/z1hkazw7.aspx

Thursday, March 22, 2012

Session variables

I'm designing like a shopping cart and have a product list which is an xml file consisting of products and prices which is loaded into a dataset then bound to a datagrid

There are buttons next to each product by clicking one of these should direct the user to another form showing the choice of product and price in textboxes, I can't load the info into the next form using session variables

My code is below

1st form code

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Set the path of XML file and schema
Dim strPath As String = Server.MapPath(".")
' Declare a dataset
Dim dsProducts As New DataSet
' Apply the XML schema to the dataset
dsProducts.ReadXmlSchema(strPath & "\Products.xsd")
' Read the XML into the data set
dsProducts.ReadXml(strPath & "\Products.xml")
DataGrid1.DataSource = dsProducts
DataGrid1.DataBind()
Session.Item("Product1") = "Jam Doughnut"

End Sub

Private Sub btnJam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJam.Click

Server.Transfer("order.aspx")

2nd form code

Dim product1 as string = session.item("Product1")

End Sub

As you can see I'm trying to create the session variables before the next form is loaded but can't seem to load these into the next form, for example if jam doughnut is selected then jam doughnut and 0.35 should appear in textboxes on the next form or if apple doughnut is selected then apple doughnut and 0.40 should appear in the texboxes on the next form instead

Any advice would be appreciated

ThanksI don't understand your problem. On your next page when you do...

<% Session.Item("Product") %>

does it list the item on the page?
So what is preventing you from using it?
If the dataset isn't too large, you might want to consider just loading the dataset into a session and then pulling the data out on each page.

Session("products") = dsProducts

then on each page you can get it back:

dim ds as DataSet = Ctype(Session("products"),DataSet)

then you have your stuff in ds...
Thanks, I'm stuck now on how to retrieve the info from the dataset

I've put session("products")= dsproducts after datagrid.databind in the form load event procedure and Dim ds As DataSet = CType(Session("products"), DataSet) in the next form

I will need to put server.transfer("order.apx")for the 5 button click event procedures depending on what button is clicked then load the required choice in the textboxes on the next form

Any advice would be appreciated

Thanks
There are buttons next to each product by clicking one of these should direct the user to another form showing the choice of product and price in textboxes

Don't use session variables then. Redirect the user to

Product.aspx?productid=2389472

Where 2389472 is the ID of the product. In Product.aspx, query the database based upon the querystring parameter and get the info you need.