Chciałbym przenieść pliki z ListView gdzie są wyświetlane z bazy danych ( konkretne przedmioty uprzednio wybrane z produktów danej kategorii sklepu ) do plików Cookies lecz za cholerę nie wiem jak te dane wyciągnąć. Nie da się bezpośrednio ( przynajmniej ja takiej wiedzy nie posiadam, a znane mi sposoby nie działają ) to w takim razie jak to obejść?
Mój kod wygląda następująco
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ProductDescription.aspx.cs" Inherits="Page_Catalog_ProductDescription" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="product_id" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="ListView1_SelectedIndexChanged">
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<ItemTemplate>
<span style="">
<%-- <asp:Label ID="product_idLabel" runat="server" Text='<%# Eval("product_id") %>' />
<br />--%>
<asp:Label ID="product_nameLabel" runat="server" Text='<%# Eval("product_name") %>' />
<br />
Opis:
<asp:Label ID="product_discriptionLabel" runat="server" Text='<%# Eval("product_discription") %>' />
<br />
Cena:
<asp:Label ID="unit_priceLabel" runat="server" Text='<%# Eval("unit_price") %>' />
<br />
<%-- MSRP:
<asp:Label ID="MSRPLabel" runat="server" Text='<%# Eval("MSRP") %>' />
<br />--%>
Dostępne rozmiary:
<asp:Label ID="available_sizeLabel" runat="server" Text='<%# Eval("available_size") %>' />
<br />
Rostępne Kolory:
<asp:Label ID="available_colorLabel" runat="server" Text='<%# Eval("available_color") %>' />
<br />
Waga sztuki:
<asp:Label ID="unit_weightLabel" runat="server" Text='<%# Eval("unit_weight") %>' />
<br />
<%-- Rozmiar:
<asp:Label ID="sizeLabel" runat="server" Text='<%# Eval("size") %>' />
<br />--%>
<%-- color:
<asp:Label ID="colorLabel" runat="server" Text='<%# Eval("color") %>' />
<br />--%>
Dostępność produktu:
<asp:Label ID="product_availableLabel" runat="server" Text='<%# Eval("product_available") %>' />
<br />
<%-- discount_available:
<asp:Label ID="discount_availableLabel" runat="server" Text='<%# Eval("discount_available") %>' />
<br />--%>
<img src="../../<%# Eval("picture_big") %>"
<br />
Ilość:<asp:TextBox Text="" runat="server" ID="tbQuantity" width="20" />
<br />
<asp:Button ID="btnAdd" runat="server" OnClick="Button1_Click" Text="Dodaj do koszyka" />
<br /></span>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ShopConnectionString %>" SelectCommand="SELECT [product_id], [product_name], [product_discription], [unit_price], [MSRP], [available_size], [available_color], [unit_weight], [size], [color], [product_available], [discount_available], [picture_big] FROM [Products] WHERE ([product_id] = @product_id)">
<SelectParameters>
<asp:QueryStringParameter Name="product_id" QueryStringField="prod_id" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
A tu kod aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Page_Catalog_ProductDescription : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie CartCookie = new HttpCookie("OrderInfo");
CartCookie.Values["ProductName"] = "";
CartCookie.Values["ProductPrice"] = "";
CartCookie.Values["ProductQuantity"] = "";
CartCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(CartCookie);
Response.Redirect("Cart.aspx");
}
}