Author |
Topic |
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-10 : 14:28:35
|
I have two dropdown in my form and when user choose from dropdowns table populates, I need to program remember those selected items from dropdowns that when user comes back to this form, it should automatically populate table again. I think I need to use string variables for that but i don't know how and where? |
|
MarkGG
Yak Posting Veteran
53 Posts |
Posted - 2005-08-10 : 14:32:04
|
I am not too sure I understand your question. So the user can choose an option from two drop downs and based on the user selection on these drop downs a table populates itself on the page? After this the user I assume can go off and check out some other things but if they come back to this form you want it to have the same table it had from the first time they filled out the forms?Can I see code for this page? |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-10 : 15:07:23
|
I haven't created the code yet, that's what is I am asking. When user comes back to this form, form should display option choosed in dropdowns. If I select a from dropdown1 and b from dropdown2, when I come back to this form my two dropdowns should remember a and b values so table can be generated auto again. What would make the remember this values? |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-10 : 17:51:31
|
Did you hit google for this? ddMyDropDown.Items.FindByValue(mydataset("MyPrimaryKey")).Selected = TrueMichael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-10 : 18:00:58
|
I have created something like this, i put this code page load part and my dropdown id is cbogroupsso I put like this Session("SelectedValue") = cbogroups.SelectedValueand I put this my sub which creates table after user choose options from dropdowns, i put in my sql like Dim selectedValue1 As String = Convert.ToString(Session("SelectedValue")) strSQL &= "WHERE groupname = '" & Session("selectedValue1") & "' "all these are not giving me error, but it is not remembering my selected options when i come back either. Where I am not doing right? |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-10 : 20:19:39
|
Ok, what you have to do is this.1. Take the session = selected value out of page load. Since the user is selecting something AFTER the page loads, you'll get the wrong value anyway.2. Make sure ViewState is enabled for your Drop Down's.3. I'm assuming there's a Button a user clicks on to "save" or "move to next step." In the OnClick event of that button, You'll need something like this:strSQL &= "WHERE groupname = '" & myDropDown.SelectedItem.Text & "' "orstrSQL &= "WHERE groupname = '" & myDropDown.SelectedItem.Value & "' "It all depends on how you set your drop down box up, and what you put for text and what you put for value.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-11 : 11:11:13
|
Thank you Michael for your help! Before I have started this thread I have done exactly what you just wrote, and my viewstate is enable too. This code was giving me right value no problem, no error, but when I come back to page all the selected values gone from dropdown it is empty again. That's why someone suggested session variables, I actually rather to use Request string variables, but i haven't done this before that I don't know how to do that, I have been searching all the google since then, couldn't find good example for that that it will show me how to do that. All I need is when I come back to page, previous values would be remembered.. Can you be able to help me to this? |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-11 : 11:18:46
|
Ok when you "come back to this page" is it from a Post Back or are you redirecting to this page somehow?How about this. Post your code behind for your ASPX page. That would help give me an idea of what is going on.Be sure to put it in the [ code ] tags.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-11 : 11:32:52
|
First, I have two dropdowns and only second one Autopostback is true, so when user clicks first one and selects value, then clicks second one and selects value and autopostback fires and generates table accordingly with selected values from dropdowns. No problem until this time all my code works fine. Then I need some sort of code that if user clicks Home to go different page, or gets out the whole .net and comes back next day when he/she clicks back to this page, I need my two dropdowns to remember what was the value from yesterday, and go ahead to give me remmember values from dropdowns and also of course it should display the table accordingly just like from yesterday it was showing everything before user get out from this page. Doesn't matter Home clicked or just log off completely. I didn't post my code because I don't have a code for this yet, all I have my GetSelected() function which generates my table according to values from dropdowns.Don't I need some sort of code in page load so when user comes back to that page boom it will get the previous values and generates that page just like it was generated yesterday? |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-11 : 11:44:54
|
Ok, if that's the case, you need to store the selected values for both of the drop down boxes in the database someplace, or possibly a cookie.Then, on PageLoad, just after you populate the dropdown boxes, set the selected item of the drop down's based on the database / cookie.ddMyDropDown.Items.FindByValue(insert cookie or database lookup here).Selected = TrueMichael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-11 : 11:45:54
|
Session will only last while the user is logged in generally. It will not last after a user log's off.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-11 : 12:04:02
|
You are right about Session. Believe or not my boss just told me this in this sentence what I need to do."THis form should remember the selected options from dropdowns that so when user comes back to it the list automatically populated. Please use the request string variables for this." That's it! How can I use request string variables? LIke you said, cookie or put it in database? I doubt it very much doesn't want me to store in database, maybe cookie, but how to do that? |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-11 : 13:58:11
|
The ideal place to store it would be a database. If you must store it in a cookie, here's a sample:'Put this in the code that executes when the second down down post's back.Dim oCookie As New HttpCookie("MyWebsiteNameHere")oCookie.Expires = Date.Now.AddMonths(12)oCookie.Values.Add("DropDownOneName", ddMyDropDown1.selectedvalue)oCookie.Values.Add("DropDownTwoName", ddMyDropDown2.selectedvalue)Response.AppendCookie(oCookie)'In your page load event, put something like this AFTER you populate the drop downs with data. Dim oCookie As HttpCookie oCookie = Request.Cookies("MyWebsiteNameHere") If Not oCookie Is Nothing Then If oCookie.HasKeys Then DropDownOne.SelectedValue = Request.Cookies("MyWebSiteNameHere").Item("DropDown1") End If End If <Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-11 : 14:30:39
|
Thanks for the example for cookie storage, but you think it is best to store in database, how this would be, just create a table would have userid and dropdown1 and 2 values and ...?Then what is my boss talking about requesting string variables? Did you understand what that means about that?Thanks Michael! |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-11 : 15:04:59
|
Your boss is not understanding some concepts or your not explaining your setup to me properly :)If you pass things in the URL, you grab them with Request.Querystring. If a user opens up http://www.mysite.com, they are not going to type in the variables needed in the URL so that you can pick the right things in th drop downs. You really should store the values in a table along with the unique idenifier for that user.So, you'd have a table that looks like this:UserID, ParamName, ParamValuewith data like 1, DropDown1, "whatever the value is"1, DropDown2, "whatever the other value is"<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-11 : 16:27:44
|
You are right. Thanks for the all help!! |
 |
|
notsosuper
Posting Yak Master
190 Posts |
Posted - 2005-08-11 : 16:59:33
|
Michael I am back! I have been searching this and I come to end, I want to use session and have this functinality work only when user still logon the system. Can you help me out about using session? YOur examples are very clear, and you are telling me where to put those also. |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2005-08-11 : 18:50:52
|
Basically, you need to replace the code that saved stuff to the cookie to save things to session.Session("DropDown1") = ddMyDropDown.SelectedValueand use Session("DropDown1") when selecting the valueWhat sort of session are you using? Look in your web.configInProc, SQLServer, Off If you are using InProc, or SQLServer, and have only one web server this will work. If this is not the case, you'll need to use SQLServer to store your state for your web farm.BTW, where are you from? Judging from your english, your's not from the USA, UK, or AUS.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda> |
 |
|
|