User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,625 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,708 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

Newbie Needs Help with this ASPX

Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Help Re: Newbie Needs Help with this ASPX

  #2  
May 7th, 2004
Originally Posted by dwhite02
I am doing this in Microsoft Visual Studio.NET as an ASP.Net Web Application.

I am new to .NET, and Am trying to learn, I just cant figure this out.

<html>
<head>
<title>Shopping Cart</title>
<script runat="server">
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow

Private Sub Page_Load(s As Object, e As EventArgs)
If Not IsPostBack Then
makeCart()
End If
End Sub

Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1

objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Cost", GetType(Decimal))

Session("Cart") = objDT
End Function

Sub AddToCart(s As Object, e As EventArgs)
objDT = Session("Cart")
Dim Product = ddlProducts.SelectedItem.Text
Dim blnMatch As Boolean = False

For Each objDR In objDT.Rows
If objDR("Product") = Product Then
objDR("Quantity") += txtQuantity.Text
blnMatch = True
Exit For
End If
Next

If Not blnMatch Then
objDR = objDT.NewRow
objDR("Quantity") = txtQuantity.Text
objDR("Product") = ddlProducts.SelectedItem.Text
objDR("Cost") = Decimal.Parse(ddlProducts.SelectedItem.Value)
objDT.Rows.Add(objDR)
End If
Session("Cart") = objDT

dg.DataSource = objDT
dg.DataBind()

lblTotal.Text = "$" & GetItemTotal()
End Sub

Function GetItemTotal() As Decimal
Dim intCounter As Integer
Dim decRunningTotal As Decimal

For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("Cost") * objDR("Quantity"))
Next

Return decRunningTotal
End Function

Sub Delete_Item(s As Object, e As DataGridCommandEventArgs)
objDT = Session("Cart")
objDT.Rows(e.Item.ItemIndex).Delete()
Session("Cart") = objDT

dg.DataSource = objDT
dg.DataBind()

lblTotal.Text = "$" & GetItemTotal()
End Sub
</script>

</head>
<body>
<form runat="server">
Product:<br>
<aspropDownList id=ddlProducts runat="server">
<asp:ListItem Value="4.99">Socks</asp:ListItem>
<asp:ListItem Value="34.99">Pants</asp:ListItem>
<asp:ListItem Value="14.99">Shirt</asp:ListItem>
<asp:ListItem Value="12.99">Hat</asp:ListItem>
</aspropDownList><br>
Quantity:<br>
<asp:textbox id="txtQuantity" runat="server" /><br><br>
<asp:Button id=btnAdd runat="server" Text="Add To Cart" onClick="AddToCart" /><br><br>
<aspataGrid id=dg runat="server" ondeletecommand="Delete_Item">
<columns>
<asp:buttoncolumn buttontype="LinkButton" commandname="Delete" text="Remove Item" />
</columns>
</aspataGrid>
<br><br>
Total:
<asp:Label id=lblTotal runat="server" />
</form>
</body>
</html>


Umm... that is all fine and dandy....but what are you trying to do, and what exactly is it that you can't figure out? Point us in the direction of your problem.

Thanks
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
All times are GMT -4. The time now is 12:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC