Click to See Complete Forum and Search --> : USING radiobuttonlist to search the database
zacksofia
03-27-2006, 11:06 AM
Hi,
I'm not sure how this is done. I have 3 pages/webform that contain sets of radio list button. Let's say this, I created 3 sets of radiobutton lists at the first page. User selects the value of each radio button and click on to a NEXT button. Same goes for the second and the last page. At the end of the last page, the user click on to the Submit button which will combining all the data/values from the radio button lists from every previous page and search through the database to return the value based on the user selections from the radio button list.
I'm trying to create something like expert system, to identify species of a plant based from the user inputs. Hope you guys can tell me how to get started. How to keep the data from the radio list in every page until the user hit the SUBMIT button in the last page?
Is it true this can be done using Session? anybody can provide some examples?
Thanks in advance. :)
zacksofia
03-27-2006, 11:07 AM
and one more thing, i'm using ASP.NET 2.0, VB language.
sirpelidor
03-27-2006, 02:17 PM
Hi, there are many ways to accomplish the same task.
The 2 most obvious way off the top of my head is a) using query string, and b) use session.
if you wanna go with (a):
on your onSubmit_Click method, just add the querystring at the end of your redirect statement, i.e: response.redirect("page2.aspx?condition1=" &rdo.SelectedValue)
keep doing it til your last page, so can get those value off by calling:
dim c1 as string = request.querystring("condition1")
then your sql statement can based on it....
select * from table where condition1 = c1 and xxx = yyy and zzz = zyzy
(b) is very similiar, just store your condition in session instead of through querystring
zacksofia
03-29-2006, 02:14 AM
I decided to use HashTable to store the values for my radiobuttonlist.
Let's say that I create a hash table in page1.
Dim hsh As New Hashtable
hsh.Add("radio1", RadioButtonList1.SelectedValue)
Session.Add("userinput1", hsh)
so the radiobutton value will be stored in the hashtabe. but if i want to add the values of the radiobuttonlist in the next page, how this is done? how can I add the new value without over writing the previous value? should I write Dim hsh as new Hastable again in the page2 ?
zacksofia
03-29-2006, 02:16 AM
Hi, there are many ways to accomplish the same task.
The 2 most obvious way off the top of my head is a) using query string, and b) use session.
if you wanna go with (a):
on your onSubmit_Click method, just add the querystring at the end of your redirect statement, i.e: response.redirect("page2.aspx?condition1=" &rdo.SelectedValue)
keep doing it til your last page, so can get those value off by calling:
dim c1 as string = request.querystring("condition1")
then your sql statement can based on it....
select * from table where condition1 = c1 and xxx = yyy and zzz = zyzy
(b) is very similiar, just store your condition in session instead of through querystring
thanks sirpelido for replying! :D
sirpelidor
03-29-2006, 02:33 AM
I decided to use HashTable to store the values for my radiobuttonlist.
Dim hsh As New Hashtable
hsh.Add("radio1", RadioButtonList1.SelectedValue)
Session.Add("userinput1", hsh)
should I write Dim hsh as new Hastable again in the page2 ?
hashtable is a type of data structure itself, in this case... you might as well past the whole hashtable from 1 aspx form to another instead of create a new one as new page is being created.
that way, u can keep calli the same code hsh.add("radio1", RadioButtonList1.SelectedValue) over and over (assuming if all your radio button is call RadioButtonList1 for all ur aspx pages) to save some work
zacksofia
03-29-2006, 02:52 AM
Yes, I wanted to use the same hashtable without losing the previous values. I can't figure out how to pass the hashtable to the next page. and to add new value in the hashtable. :confused: I've tried to put this in the new page
Dim hsh2 as HashTable
hsh2 = PreviousPage.Session("hsh")
but it's not working. :(
sirpelidor
03-29-2006, 01:28 PM
I can't figure out how to pass the hashtable to the next page.
Suppose you have 2 aspx pages name page1.aspx and page2.aspx, to pass a hashtable to next page using session varable
in page1.aspx, to store your hashtable into a session:
Session.Add("mysession", hsh)
in page2.aspx, to retreive your hashtable from a session:
Dim hsh As Hashtable
hsh = CType(Session.Item("mysession"), Hashtable)