Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2004, 03:46 AM
Registered User
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating shopping cart

Hello..

I'm doing my shopping cart project in asp.net recently. But I do not know how to display mulitple datagrid's rows on the shopping cart's web page.

When I click on "Add to Cart" button on one web page, it will response redirect me to the shopping cart's page, but when i want to add more item on the shopping cart. It displays only one row on the datagrid. So how am i going to do that.

Hope that u can help me... Thanks u in advance..
 
Old April 10th, 2004, 12:15 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

How are you getting to the datagrid? Can you post the relevant bits of code for the datagrid?
 
Old April 11th, 2004, 02:57 AM
Registered User
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for replying me...
Your help is really precious to me..

Actually, I'm doing a reservation cart facilities for my proj. (named WISE LIBRARY proj.)
Thought that saying shopping cart might be the same, so I posted the topic as shopping cart. But found out that I need to explain my problems more clearer, so that u can help me...

I do my project using 3-tiers.
 1. Data Layer using ---- Class Library
 2. Business Logic Layer using ---- ASP.NET Web Service
 3. Presentation Layer using ---- ASP.NET Web Application

In the BusinessLogicLayer, I Add Reference to DataLayer.
Then, in the PresentationLayer, I Add Web Reference to BusinessLogicLayer.

Here are my codings:

[u]DataLayer -- ReservationData.vb</u>

Imports System.Data.OleDb

Public Class ReservationData

    Dim ConStr As String
    Dim cn As OleDbConnection
    Private m_Item As Item

    Public Sub New()
        ConStr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\inetpub\wwwroot\ReservationData\WISELIBRARY.mdb "
        cn = New OleDbConnection(ConStr)
    End Sub

    'Search for an item in the database using SQL statement
    Public Function SearchItemDetails(ByVal strSearch As String) As DataSet

        Dim da As New OleDbDataAdapter("SELECT * FROM Item WHERE Author LIKE '%" & strSearch & "%' OR Title LIKE '%" & strSearch & "%' OR Publisher LIKE '%" & strSearch & "%'", cn)
        Dim ds As New DataSet
        cn.Open()
        da.Fill(ds)
        cn.Close()
        Return ds
    End Function

    'Search for the Item Status in database
    Public Function GetItemStatus(ByVal strSQL As String) As DataSet

        Dim da As New OleDbDataAdapter("SELECT * FROM Branch b INNER JOIN Item i ON b.BranchID = i.BranchID WHERE Title='" + strSQL + "'", cn)
        Dim ds As New DataSet
        cn.Open()
        da.Fill(ds)
        cn.Close()
        Return ds
    End Function
End Class

[u]BusinessLogicLayer -- ReservationService.vb</u>

Imports System.Web.Services

<System.Web.Services.WebService(Namespace := "http://tempuri.org/ReservationBizLogic/ReservationService")> _
Public Class ReservationService
    Inherits System.Web.Services.WebService

    <WebMethod()> Public Function SearchKeyWords(ByVal strSearch As String) As DataSet

        Dim dl As New ReservationData.ReservationData
        Return (dl.SearchItemDetails(strSearch))
    End Function

    <WebMethod()> Public Function SearchItemStatus(ByVal strSQL As String) As DataSet

        Dim dl As New ReservationData.ReservationData
        Return (dl.GetItemStatus(strSQL))
    End Function

    <WebMethod()> Public Function GetAuthor(ByVal ds As DataSet) As String
        Dim Author As String = ds.Tables(0).Rows(0)(10)
        Return Author
    End Function

    <WebMethod()> Public Function GetPublisher(ByVal ds As DataSet) As String
        Dim strPublisher As String = ds.Tables(0).Rows(0)(14)
        Return strPublisher
    End Function

    <WebMethod()> Public Function GetTitle(ByVal ds As DataSet) As String
        Dim strTitle As String = ds.Tables(0).Rows(0)(11)
        Return strTitle
    End Function

    <WebMethod()> Public Function GetCallNo(ByVal ds As DataSet) As String
        Dim strCallNo As String = ds.Tables(0).Rows(0)(21)
        Return strCallNo
    End Function

    <WebMethod()> Public Function GetDes(ByVal ds As DataSet) As String
        Dim strDes As String = ds.Tables(0).Rows(0)(18)
        Return strDes
    End Function

    [u]'Here is the problems I encounter</u>
<WebMethod()> Public Function GetDSCart(ByVal dv As DataView, ByVal strItemID As String) As DataTable

        Dim ds As DataSet
        Dim dr As DataRow
        Dim Cart As DataTable = New DataTable
    Dim arr1 As New ArrayList
        Dim arr2 As New ArrayList
        Dim arr3 As New ArrayList

        For Each dr In Cart.Rows

            arr1.Add(dv.Item)

            arr2.Add(dv.Item)

            arr3.Add(dv.Item)

            Cart.Columns.Add(New DataColumn("BranchName"))
            Cart.Columns.Add(New DataColumn("Title"))
            Cart.Columns.Add(New DataColumn("Type"))

            dr = Cart.NewRow()
            dr(0) = arr1
            dr(1) = arr2
            dr(2) = arr3
            Cart.Rows.Add(dr)
        Next
        Return Cart
    End Function
End Class


[u]PresentaionLayer</u>

1. I have a search engine for searching a book or other items.

   [u]ReservationSearch.aspx.vb</u>

'This call my businessLogic layer function
Dim bl As New ReservationBizLogic.ReservationService

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Session("dsSearch") = bl.SearchKeyWords(txtSearch.Text)
        Response.Redirect("ReservationSearchResult.aspx")
    End Sub


2. Here display a list of search results.

   [u]ReservationSearchResult.aspx.vb</u>

Public Class ReservationSearchResult
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgSearchResult.DataSource = Session("dsSearch")
        dgSearchResult.DataBind()
    End Sub

    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Response.Redirect("ReservationSearch.aspx")
    End Sub


3. Here display the Item status.

   [u]ReservationStatus.aspx.vb</u>

Public Class ReservationStatus
    Inherits System.Web.UI.Page

    Dim bl As New ReservationBizLogic.ReservationService

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ds As DataSet = bl.SearchItemStatus(Request.QueryString("topic"))

        lblTitleName.Text = bl.GetTitle(ds)
        lblAuthorName.Text = bl.GetAuthor(ds)
        lblPublisherName.Text = bl.GetPublisher(ds)
        lblDescrip.Text = bl.GetDes(ds)

        dgItemStatus.Columns(1).Visible = False
        dgItemStatus.DataSource = ds
        dgItemStatus.DataBind()

        Session("ds") = ds

    End Sub

    Private Sub dgItemStatus_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgItemStatus.ItemCommand

        Dim strItemIDCell As TableCell = e.Item.Cells(1)
        Dim strItemID As String = strItemIDCell.Text

        If e.CommandName = "Select" Then

    Dim ds As DataSet = Session("ds")
    Dim dv As DataView = New DataView(ds.Tables(0))
    dv.RowFilter = "ItemID='" & strItemID & "'"

        bl.GetDSCart(dv, strItemID)

        End If
    End Sub

    Private Sub dgItemStatus_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgItemStatus.SelectedIndexChanged
        Response.Redirect("ReservationCart.aspx")
    End Sub

    Private Sub btnBackResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackResult.Click
        Response.Redirect("ReservationSearchResult.aspx")
        Session("ds") = ""
    End Sub
End Class

4. Here display the Reservation Cart.

   [u]ReservationCart.aspx.vb</u>

Public Class ReservationCart
    Inherits System.Web.UI.Page

    Dim bl As New ReservationBizLogic.ReservationService

    'Here is my problems
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'What should I do over here?
    Dim dt As DataTable = bl.GetDSCart(???,???)
        dgReCart.DataSource = dt
        dgReCart.DataBind()
    End Sub

   Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click

    'After the user confirms to reserve certain item, I need to save it into the database.
        'How am I going to do that?

    End Sub
End Class


Btw, I do not save the reservation cart details into the database when the user clicks on the Item he/she wants. As this will reduce the performance.

I save the reservation details only when the user confirms to reserve all items in the cart.

Hope to receive ur reply soon.

Hope that u can help me... Thanks u in advance...
 
Old April 11th, 2004, 08:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This is an awful lot of code for someone who has never seen it to grasp. What the exact problem is is not clear to me yet.

One immediate (potential) problem I see is that you have a web method that returns a DataTable. I have not had luck getting this to work. I think this is a limitation of what types of objects can be returned by web methods. Instead of a DataTable, you can return a DataSet with that one table in it.

Another problem I see is in the GetDSCart method. You are adding columns to a DataTable every in each iteration of the for each loop. Also, I'm not really sure what your intention is with that method to begin with. It looks like you are just generating a DataTable from a DataView with this method. And you are using several array lists that are being set as the value of DataRow columns. That whole method doesn't make any sense to me.

In the ReservationCart page, you say you are not sure what you should be doing to populate the datagrid. Well, I'm not really sure either. If you aren't saving the cart details until confirmation, then how do you expect to get them from page to page? Isn't some of this data in the DataSet that you saved into the session?

Perhaps a written paragraph explaining the process you are using would be more helpful for us then simply posting all the code. It's hard to get thru if you aren't sure what exactly is going on, or what is desired.

Peter
-------------------------
Work smarter, not harder
 
Old April 11th, 2004, 06:16 PM
Registered User
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for replying me..
I'm sorry for the previous postings.

What I want to do this that I want to allow user to click on the reserve item (which is like the shopping cart's "Add to Cart"), then they will be bring to a web page where they can see item in the cart. I do not want to store the details of the cart into the database but store into the dataset. Then, when the user confirms all items in the cart, it will be stored into the database.

I need a webpage to allow user to choose item they want to be in the cart. And a webpage to display the cart.

Without saving details of the cart into the database, I need arraylist to store the details of the items in the cart, right? So how should I code these (cart)?

This is what I intend to do.

My english is quite poor. So hope that u can understand what I'm trying to convey.

If it is not clear, pls do reply me. I need ur help.

Thanks.
 
Old April 12th, 2004, 01:39 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I would imagine that the technique you are using for the search functionality would be suitable for the reservation "cart" as well. Save a dataset or arraylist of the user's reservations in the session and retrieve it where needed. Then when the user comfirms their reservations you commit all the items in the "cart" to the database.
 
Old April 12th, 2004, 11:32 PM
Registered User
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for ur replying... U got the idea I want to implement. I code it out already but there is error in my coding.

It states that "Object reference not set to an instance of an object" at line 4. But I did "new" my object.

Here is my bits of code:

1 <WebMethod()> Public Function GetDSCart() As DataSet
2 Dim dl As New ReservationData.ReservationData
3 Dim dsSession As New DataSet
4 dsSession = Session("ds2")
5 Dim strItemID As String = Session("ItemID")
6
7 If (IsNothing(dsSession)) Then
8 Dim dsReserve As New DataSet
9 dsReserve = dl.GetReserveItemDetails(strItemID)
10 Session("ds2") = dsReserve
11 Return dsReserve
12 Else
13 Dim dsReserve As DataSet = dl.GetReserveItemDetail(strItemID)
14
15 For Each dr As DataRow In dsSession.Tables(0).Rows
16 dr = dsSession.Tables(0).NewRow()
17 dr(0) = dsReserve.Tables(0).Rows(0)(0)
18 dr(1) = dsReserve.Tables(0).Rows(0)(1)
19 dsSession.Tables(0).Rows().Add(dr)
20 Next
21 Session("ds2") = dsSession
22 Return dsSession
23 End If
24 End Function

What is my code error? How should I actually code it?

Thanks u again. :)
 
Old April 13th, 2004, 02:59 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is no code error. The problem is that when you request a value from the session collection that does not yet exist, the session collection indexer method (the default method when you use Session() ) returns Nothing.

You don't actually need to New the dataset object because you are going to set it from the object that's in the session (if it's there). Whenever you need to retrieve a value from session that might not be there, you should check that it exists:

If Not Session("ds2") Is Nothing Then
    dsSession = Session("ds2")
End If

If it should be there, but this is still failing, then you have a different problem, and one that I can't answer.

Something else I noticed...
On line 3, you set the dsSession variable to a new DataSet. Later, at line 7, you test if it's nothing. If you Dim it to a new DataSet and you have the proper check for whether or not the dataset is in the session collection, then you'll never reach the True block of the If branch because the object will be either a new dataset, or the dataset from the session, but never Nothing.

Peter
-------------------------
Work smarter, not harder
 
Old April 14th, 2004, 09:36 AM
Registered User
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot... Your reply really help me a lot...
 
Old April 15th, 2004, 05:39 AM
Registered User
 
Join Date: Apr 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello...

I have checkbox in my datagrid. The checkbox is for the user to check and clicks on the button delete(which is not in the datagrid). And it will delete that row of the datagrid. I need to use e.Item.Cell(1) to retrieve the id from the datagrid so that i can delete my data belongs to the id. But I do not know how to code it.

I only know that if the user check the checkbox, it will become true in my codes.

Here is bits of my code:

Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click

        Dim oDataGridItem As DataGridItem
        Dim chkRemove As System.Web.UI.WebControls.CheckBox
        Dim strItemID As String
        Dim strItemIDCell As TableCell = e.Item.Cells(1)
        Dim strItemID As String = strItemIDCell.Text

        For Each oDataGridItem In dgReCart.Items

            chkRemove = oDataGridItem.FindControl("chkDelete")
            If chkRemove.Checked Then
                bl.DeleteItemFrCart(strItemID)
                RefreshGrid()
            End If
        Next
    End Sub

So, how am I going to solve this problems. As the eventargs is not DataGridCommandEventArgs.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Shopping cart help rsm42 ASP.NET 1.0 and 1.1 Basics 3 December 9th, 2006 06:09 AM
Problem Creating Shopping Cart Object jazzcatone ASP.NET 2.0 Basics 2 April 24th, 2006 08:46 PM
shopping cart xipnl BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 June 10th, 2005 07:00 PM
Shopping cart Manoj babu General .NET 0 February 14th, 2005 04:20 AM
shopping cart isheikh BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 8th, 2004 04:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.