购物车网站 [英] shopping cart website

查看:87
本文介绍了购物车网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友
正在开发购物网站
在主页上,我在gridview中有项目列表,用户必须在其中选择并选择数量.
我在 Stringbuilder变量中得到了选定的值 现在正在将变量传递到购物车中的下一页.
我如何获得单个值,因为m获得了附加值.
一旦获得值,我就必须在gridview中再次显示选定的值.怎么做 ?请帮助
以下是我到目前为止所做的事情

hello friends
am developing shopping website
on home page i have list of items in gridview where the user has to select and choose the quantity.
I have got the selected values in Stringbuilder variable
Now am passing the variables to next page in shopping cart.
How do i get the individual values, because m getting appended values.
And once i get the values i have to display the selected values again in a gridview. how to do ? please help
Following is wat i have done till now

protected void checkoutBtn_Click(object sender, EventArgs e)
   {
       bool selected = false;


       StringBuilder ProductName = new StringBuilder();
       StringBuilder Quantity = new StringBuilder();
       string[] qua=null;
       // Select the checkboxes from the GridView control

       for (int i = 0; i < GridView1.Rows.Count; i++)
       {
           string[] name = new string[GridView1.Rows.Count];
           qua = new string[GridView1.Rows.Count];
           GridViewRow row = GridView1.Rows[i];
           bool isChecked = ((CheckBox)row.FindControl("ProductSelector")).Checked;

           if (isChecked)
           {
               // Column 0 is the name column

               ProductName.Append(GridView1.Rows[i].Cells[0].Text);
               Quantity.Append(((DropDownList)row.FindControl("DropDownList1")).SelectedItem.Value);
              // name[i] = GridView1.Rows[i].Cells[0].Text;
             //  qua[i] = ((DropDownList)row.FindControl("DropDownList1")).SelectedItem.Value;

           }

       }

       // prints out the result
       Response.Redirect("Basket.aspx?name=" + ProductName.ToString() + "&quantity=" + Quantity.ToString());


   }

推荐答案

乍一看,您似乎正在使用客户端网格(即使它是服务器控件)作为存储空间用于购物车.

虽然没有直接回答您的问题,但确实有一些建议.

我认为您应该重新考虑如何构建购物车.您是否考虑过购物车对象,也许带有商品清单?您可以将其保存在Session中.如果打算有任何卷,则当然可以使用数据库根据用户ID或会话ID存储用户的行.

出于多种原因,这是首选方法,其中包括浏览器冻结,用户暂时离开站点,可以选择保存购物车等.

然后,Basket.aspx可以简单地绑定到您的集合(在内存中或从数据库中),而您不必传递查询字符串参数.

欢呼.
By first glance it appears that you''re using a client-side grid (even though it''s a server control) as your storage for the cart.

While not answering your question directly, I do have some suggestions for you.

I think you should reconsider how you''re building the cart. Have you thought about a shopping cart object, perhaps with a list of items? You could save that in Session. If you intend to have any volume, you would of course use a database to store the rows of the user based either on user ID or session ID.

This is the preferred approach for a number of reasons including browser freezes, user leaving the site temporarily, having the option to save a cart, etc.

Basket.aspx could then simply bind to your collection (either in memory or from the db) and you wouldn''t have to pass in query string params.

Cheers.


您正在使用循环遍历GridView的所有行,并将内容附加到您的ProductNameQuantity字符串,所以毫不奇怪结果如您所描述.您应使用某种形式的列表(T) [
You are using a loop to go through all rows of your GridView and appending the content to your ProductName and Quantity strings, so it is little wonder that the results are as you describe. You should use some form of List(T)[^] class to separate the individual items.


这篇关于购物车网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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