Hi, I am developing code for shopping cart. There I need to add Items in Shopping Cart. For this purpose I am storing values using Cookies using jquery And reading them using C# And simultaneously I have to use Delete button to expire the cookies items. Here is my code below:
Shopping_Cart.aspx:
<script>
function SetEhsCookies(serviceID,cityID,vendorID)
{
var cookieValue ="" + serviceID + "," + cityID + "," + vendorID + "";
$.cookie('ehsCookie0001', cookieValue, { expires:7, path: '/' });
alert(cookieValue);
}
</script>
<asp:ListView ID="lstCookies" runat="server">
<LayoutTemplate>
<table summary="Shopping cart" runat="server">
<tr>
<th class="goods-page-image">Service Image</th>
<th class="goods-page-quantity">Service Name</th>
<th class="goods-page-description">Service Description</th>
<th class="goods-page-price">Selling Price</th>
<th class="goods-page-total" colspan="2">Total</th>
<th class="del-goods-col"></th>
</tr>
<tr runat="server" id="itemPlaceholder"></tr>
</table>
<asp:DataPager ID="dataPagerNumeric" PagedControlID="lstCookies" OnPreRender="dataPagerNumeric_PreRender"
runat="server" PageSize="5">
<Fields>
<asp:NumericPagerField ButtonCount="5"
NumericButtonCssClass="numeric_button"
/>
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<table summary="Shopping cart">
<tr>
<td class="goods-page-image">
<a href="javascript:;">
<img src='<%#Eval("ServiceImage") %>' alt="ServiceImage" runat="server">
<%-- <asp:Image ID="IMG1" runat="server" ImageUrl='<%#Eval("ServiceImage") %>' alt='<%#Eval("ServiceName") %>' />--%>
</a>
</td>
<td class="goods-page-quantity">
<div class="product-quantity">
<p id="product-quantity" class="form-control input-sm">
<%#Eval("ServiceName") %>
</p>
</div>
</td>
<td class="goods-page-description">
<h3><a href="javascript:;"><%#Eval("ServiceName") %></a></h3>
<%--<p><strong>Item 1</strong> - Type: Bed; Size: single</p>--%>
<em>More info is here</em>
</td>
<td class="goods-page-price">
<strong><span>₹</span><%#Eval("SellingPrice") %></strong></td>
<td class="goods-page-total">
<strong><span>₹</span><%#Eval("SellingPrice") %></strong></td>
<td class="del-goods-col">
<a class="del-goods" href="javascript:;"> </a>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:ListView>
Shopping_Cart.aspx.cs:-
protected void Page_Load(object sender, EventArgs e)
{ if (!Page.IsPostBack)
{
if (Request.QueryString["serviceID"] != null && Request.QueryString["CityID"] != null && Request.QueryString["VendorID"] != null)
{
int serviceID = Convert.ToInt32(Request.QueryString["serviceID"]);
int cityID = Convert.ToInt32(Request.QueryString["CityID"]);
int vendorID = Convert.ToInt32(Request.QueryString["VendorID"]);
//ScriptManager.RegisterStartupScript(this,GetType(), "myFunction", "myFunction();", true);
//Page.RegisterClientScriptBlock(this.Get"SetEhsCookies", string.Format("SetEhsCookies ({0});", serviceID), true);
//Page.RegisterClientScriptBlock("SetEhsCookies", "<script>SetEhsCookies('" + serviceID + "','" + cityID + "','" + vendorID + "');</script>");
ClientScript.RegisterStartupScript(this.GetType(), "SetEhsCookies", "SetEhsCookies('" + serviceID + "','" + cityID + "','" + vendorID + "');", true);
Show_Cart();
}}
private void Show_Cart()
{
if (Request.Cookies["ehsCookie0001"] != null)
{
string cookie = Request.Cookies["ehsCookie0001"].Value;
cookie = Server.UrlDecode(cookie);
string[] cookie_IDs = cookie.Split(',');
int serviceID = Convert.ToInt32(cookie_IDs[0]), cityID = Convert.ToInt32(cookie_IDs[1]), vendorID = Convert.ToInt32(cookie_IDs[2]);
objEntity.serviceID = serviceID;
objEntity.CityId = cityID;
objEntity.VendorID = vendorID;
DataSet ds = new DataSet();
ds = objBAL.Get_Cart_Data(objEntity);
lstCookies.DataSource = ds;
lstCookies.DataBind();
}
}
using this code I am able to show only one cookie data whose Id is '
ehsCookie0001
'
But my requirement is : As I add more items in cookies then this id "ehsCookie0001" should increase with 1 and next values should store in this cookie with incremented Cookie ID. And while retrieving them it should split this id with accessing only last four digit, e.g.:
1. ehsCookie0001
2.ehsCookie0002
3. ehsCookie0003
and so on.. In this cookie id every next data should be stored and while accessing these cookies in codebehind it should split this id in following manner,e.g:
1. 0001
2.0002
3.0003
And on this behalf of cookie ID all data should be displayed in ListView. Simultaneously It should use delete button to expire cookie of particular row. Kindly help me out.