Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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());


   }
Posted
Comments
#realJSOP 22-Aug-11 14:33pm    
What does your data string look like? We can't possibly guide you unless you give us more info.
Noel3090 22-Aug-11 14:42pm    
it looks likes this
ProductName
Nokia 6120 classicReliance 3G Tab

and for quantity
13

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.
 
Share this answer
 
Comments
Noel3090 22-Aug-11 14:45pm    
No they specifically mentioned to use gridview . cant i do with gridview??
TheyCallMeMrJames 22-Aug-11 15:45pm    
That's fine, you can use a gridview to display the data, but by no means should you use it to STORE the data. As I said, use a list of items in a shopping cart object (for example List<Product>). Cheers.
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.
 
Share this answer
 
v2
Comments
Noel3090 22-Aug-11 14:57pm    
Yea thanks. Can you please tell me how to do it. coz am new to this
Richard MacCutchan 22-Aug-11 15:01pm    
Go to that link and learn about the List(T) class. You can also Google for other samples.
Noel3090 22-Aug-11 15:08pm    
how to get values into that list if i create like this
List string data=new List string();
Noel3090 22-Aug-11 15:14pm    
ok sir i got the values. but how to pass that info to other page nd retrieve it?
Richard MacCutchan 22-Aug-11 15:28pm    
If you do not understand how to use something like the List class, or how to pass information around in a web application then I think you should perhaps step back and work on something simpler. There are lots of sample web applications that you can find through Google but unless you understand at least the majority of the code then you are unlikely to get it working properly.

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