如何将值从Cookie传递到网格视图? [英] How to pass value from cookie to grid view ?

查看:80
本文介绍了如何将值从Cookie传递到网格视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有脚趾页面,第一页有按钮事件添加到购物车,并且此方法已放入其中

I have toe pages the first page there is button event add to cart and this method into it

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);
        }
    }


现在,它将是cookie中的多个项目

我想将这些项目传递到gridview购物车,该购物车在另一页中显示cookie中的项目

这样的设计视图中的网格视图


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

<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>




请帮助我

thanx




help me please

thanx

推荐答案

您可以尝试做的是,访问网格视图所在页面上的Cookie,读取Cookie中的产品ID,然后从这些ID的数据库,并将该列表或数据集绑定到网格.希望这能回答您的问题

干杯
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


这篇关于如何将值从Cookie传递到网格视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆