User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 375,229 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,264 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

Saving ListBox selected Item in Cookies

Join Date: May 2008
Posts: 5
Reputation: toton is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toton toton is offline Offline
Newbie Poster

Re: Saving ListBox selected Item in Cookies

  #2  
May 11th, 2008
All the ListBox values are storing in Cookies and fetching from there also.
But my requirment is different:
In all the ListBox's there are multi selection facility.But in this case if I select 2 values from a single ListBox only the first one is saving in the cookies.
As a result when I clicking in the "LoadQuery" instead of 2 only 1 value is selected showing.

2) There are 13 ListBox's in this page and there may be situation that out of 13 only 3 has been selected by the user.But in this case as per my code I have to select all the ListBoxes otherwise it is giving error.
What will be the if condition?

Please let me know with this multi selection facility is this approach a right one?Means storing values in Cookies?
If there any other approach? could you please help me as per my requirment?

My Code:
  1. private void SaveQuery_Click(object sender, System.EventArgs e)
  2. {
  3. HttpCookie htk=new HttpCookie("toton");
  4. HttpCookie htk1=new HttpCookie("toton1");
  5. htk.Value=ListBox1.SelectedItem.Text;
  6. htk1.Value=ListBox2.SelectedItem.Text;
  7. htk.Expires=DateTime.MaxValue;
  8. htk1.Expires=DateTime.MaxValue;
  9. Response.Cookies.Add(htk);
  10. Response.Cookies.Add(htk1);
  11. }
  12.  
  13.  
  14. private void LoadQuery_Click(object sender, System.EventArgs e)
  15. {
  16. HttpCookie cookie = Request.Cookies["toton"];
  17. if (cookie != null)
  18. {
  19. ListBox1.SelectedValue = cookie.Value;
  20. }
  21. HttpCookie cookie1 = Request.Cookies["toton1"];
  22. if (cookie1 != null)
  23. {
  24. ListBox2.SelectedValue = cookie1.Value;
  25. }
  26. }

In this scenarion I am taking 2 ListBoxes as an example.
Waiting for your response...............
Last edited by peter_budo : May 11th, 2008 at 12:26 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
All times are GMT -4. The time now is 4:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC