Click here to Skip to main content
15,889,354 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have toe pages the first page there is button event add to cart and this method into it

C#
private void AddToShoppingCart(int ProductID)
    {
        if (Request.Cookies["ShoppingCart"] == null)
        {
            HttpCookie oCookie = new HttpCookie("ShoppingCart");
            //Set Cookie to expire in 3 hours
            oCookie.Expires = DateTime.Now.AddHours(3);
            oCookie.Value = ProductID.ToString();
            Response.Cookies.Add(oCookie);
        }
        else
        {
            bool bExists = false;
            char[] sep = { ',' };
            HttpCookie oCookie = (HttpCookie)Request.Cookies["ShoppingCart"];
            //Set Cookie to expire in 3 hours
            oCookie.Expires = DateTime.Now.AddHours(3);
            //Check if Cookie already contain same item
            string sProdID = oCookie.Value.ToString();
            string[] arrCookie = sProdID.Split(sep);
            for (int i = 0; i < arrCookie.Length; i++)
            {
                if (arrCookie[i].Trim() == ProductID.ToString().Trim())
                {
                    bExists = true;
                }
            }
            if (!bExists)
            {
                if (oCookie.Value.Length == 0)
                {
                    oCookie.Value = ProductID.ToString();
                }
                else
                {
                    oCookie.Value = oCookie.Value + "," + ProductID;
                }
            }
            //Add back into  the Response Objects.
            Response.Cookies.Add(oCookie);
        }
    }

Now it will be more than one item in the cookie

I want to pass those items to gridview cart which in another page to show items which in cookies

the grid view in design view like that

XML
<asp:GridView ID="grdCart" runat="server" AutoGenerateColumns="False"
    DataKeyNames="ItemID" CellPadding="4"
    ForeColor="Black" GridLines="Horizontal" Height="260px" Width="856px"
    BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
        <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageUrl","~/Images\\{0}") %>'/>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="ProductName" HeaderText="Product" ReadOnly="True" />
        <asp:BoundField DataField="Quantity" HeaderText="Quantity" />
        <asp:BoundField DataField="Price" DataFormatString="{0:c}" HeaderText="Price" ReadOnly="True" />
        <asp:BoundField DataField="SubTotal" DataFormatString="{0:c}" HeaderText="Total"
            ReadOnly="True" />
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
    </Columns>
    <EmptyDataTemplate>
        Your Shopping Cart is empty, add items
        <a href="Itemss.aspx">Add Products</a>
    </EmptyDataTemplate>
    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F7F7F7" />
    <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
    <SortedDescendingCellStyle BackColor="#E5E5E5" />
    <SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>



help me please

thanx
Posted
Updated 17-Apr-12 5:14am
v2

1 solution

what you can try doing is, access the cookie on the page where your grid view is, read the product ids in your cookie, fetch the data from the database for those ids and bind that list or dataset to your grid. Hope this answers your question

Cheers
 
Share this answer
 
Comments
Sarah Mohammed77 18-Apr-12 19:13pm    
how to fetch the data from database
I got ids like that from cookies( 1,2,3 )
and when I select it from database itgives me error syntax
(select*from TItem where ItemID=1,2,9)
how can i select more than one row ???
I.explore.code 19-Apr-12 3:59am    
your SQL query is the wrong syntax. It should be "select * from TItem where ItemID in (1,2,9)". Make sure your queries are constructed the right way throughout your application.
Sarah Mohammed77 19-Apr-12 9:31am    
thank you soooo much
I.explore.code 19-Apr-12 15:23pm    
If my reply solved your problem, can you please accept this as an answer so people know that this has been resolved? :) would love it if u could rate the answer as well ;) Cheers.
Sarah Mohammed77 20-Apr-12 15:15pm    
I select those column from database DataTable dtt = d.select("select ItemID,ItemName,SellingPrice,ImageUrl from TItem where ItemID in ("+oCookie.Value+")");
but there is two column isn't in database Count and total but there is in gridview
he give me error(A field or property with the name 'total' and 'count' was not found on the selected data source).
how can I add them ????

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