Second SELECT-box doesn't show the selected value as SELECTED

Hi!

I usually find what I look for in the other threads, but now I've spent two weeks searching and I still can't work this out, even though I'm sure the solution is easy:(
Why doesn't my second dropdown-list show the selected value Arb (which shows in the url-window as for example myPage.asp?Ar=1976&Arb=1987) as selected? It manages to use the Ar-variable for the first SELECT-box, but the second box always has the first querystring-value selected, as if Arb="". I've also tried using a second sql-query, doing exactly as with the first SELECT-box, without success.
Is it because I'm using the same request.querystring twice? This is my simplified code:
============================================

<%Dim conn, rs, sql, Ar, Arb
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("myDB.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT DISTINCT Ar FROM myTable ORDER BY Ar"
rs.Open sql,conn
Ar=request.querystring("Ar")
%>
<form method="get">
<select name="Ar">
<%
do until rs.EOF
response.write "<option"
if rs.fields("Ar")=Ar then
response.write " selected"
end if
response.write ">"
response.write rs.fields("Ar")
rs.MoveNext
loop
%>
</select>
<%
if Ar="" then
%>
<input type="submit" value="Start">
</form>
<%
else
%>
<select name="Arb">
<%
rs.MoveFirst
do until rs.EOF
response.write "<option"
if rs.fields("Ar")=Arb then
response.write " selected"
end if
response.write ">"
response.write rs.fields("Ar")
rs.MoveNext
loop
%>
</select>
<%
if Arb="" then
%>
<input type="submit" value="End">
</form>
<%
rs.close
conn.Close
set rs=Nothing
set conn=Nothing
End If
End If
%>
=========================================
Thanx
0
mliungman
8/14/2003 8:27:55 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies
905 Views

Similar Articles

[PageSpeed] 28

Doesn't look like you ever set the Arb variable.  Try adding Arb=Request.QueryString("Arb") to see if that works.
0
racheli
8/14/2003 8:39:33 PM
I can't set Arb=request.querystring("Arb") since there is no Arb-column in the database. I'm using the data in the Ar-column twice since it contains years and I'm trying to choose a Startyear and a Endyear. From there I want to show the data BETWEEN these years.

Or have I misunderstood the request.querystring-syntax?
0
mliungman
8/20/2003 8:59:18 PM
Request.QueryString() isn't related to the columns in your database.  Since you have Ar=Request.QueryString("Ar") I was assuming you were passing in the values you wanted Ar and Arb to be in your querystring like this (or something close to this):  webform1.aspx?ar=1990&arb=2005.  In this case, Arb=Request.QueryString("Arb") will set Arb=2005.

Another thing you could try just to see if your code to create the second option tag is working, is just set Arb="2005" or whatever year you want at the beginning of your code.
0
racheli
8/20/2003 11:09:37 PM
You are quite right! I misunderstood the syntax... I tried setting Arb=request.querystring("Arb") just after replying to your post, and it worked.

Now I'm trying to filter out distinct years from my database with dates in one column. Any suggestions? One solution that works is to insert a YEAR-column in the database and then use DISTINCT in the sql-statement, but I would like to minimize the database as much as possible. Is it possible to use DISTINCT when filtering the recordset, or to search only the year-part of the date in the database?
Thanks for the help so far!
0
mliungman
8/21/2003 9:07:50 PM
This should get you what you want:

SELECT DISTINCT DATEPART(year, Ar) as aryear FROM myTable ORDER BY aryear
0
racheli
8/21/2003 10:22:38 PM
Exactly what I was looking for! However, I get the following errormessage (translated from Swedish):

Microsoft JET Database Engine (0x80004005)
The ORDER BY-instruction (Datum) ..."doesn't work with"...DISTINCT.

The web tells me that 0x80004005 is an access-error, but I can read the rest of the database. When searching the web I find this on MSDN Microsofts site. Not sure how it helps me though...

Syntax
[ ORDER BY { order_by_expression [ ASC | DESC ] } [ ,...n] ]
Arguments
order_by_expression
Specifies a column on which to sort. A sort column can be specified as a name or column alias (which can be qualified by the table or view name), an expression, or a nonnegative integer representing the position of the name, alias, or expression in select list.
Multiple sort columns can be specified. The sequence of the sort columns in the ORDER BY clause defines the organization of the sorted result set.
The ORDER BY clause can include items not appearing in the select list. However, if SELECT DISTINCT is specified, or if the SELECT statement contains a UNION operator, the sort columns must appear in the select list.
Furthermore, when the SELECT statement includes a UNION operator, the column names or column aliases must be those specified in the first select list.

Any suggestions?
Thanks for the great help so far!
0
mliungman
8/23/2003 10:04:30 PM
Just wanted to finish this thread.

I used SELECT DISTINCT LEFT(Date,4) instead, and it works fine. It seems I couldn't use the DATEPART statement. I don't know why. I also use YEAR later on in my code, it's just the DATEPART I never managed to understand completely.
It's a good thing that there are many ways to achieve the same goal!
Martin
0
mliungman
11/30/2003 6:50:21 PM
Reply:

Similar Artilces:

superreview requested: [Bug 269318] TAB doesn't start from selection text after mouse click : [Attachment 166255] If element gets focused, move selection to focus if focus isn't already inside the s
Aaron Leventhal <aaronleventhal@moonset.net> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 269318: TAB doesn't start from selection text after mouse click https://bugzilla.mozilla.org/show_bug.cgi?id=269318 Attachment 166255: If element gets focused, move selection to focus if focus isn't already inside the selection. mLastFocusedWith is no longer needed for making tab not move relative to selection after a mouse click https://bugzilla.mozilla.org/attachment.cgi?id=166255&action=edit ...

superreview granted: [Bug 269318] TAB doesn't start from selection text after mouse click : [Attachment 166255] If element gets focused, move selection to focus if focus isn't already inside the sel
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 269318: TAB doesn't start from selection text after mouse click https://bugzilla.mozilla.org/show_bug.cgi?id=269318 Attachment 166255: If element gets focused, move selection to focus if focus isn't already inside the selection. mLastFocusedWith is no longer needed for making tab not move relative to selection after a mouse click https://bugzilla.mozilla.org/attachment.cgi?id=166255&action=edit ------- Addition...

superreview requested: [Bug 112281] ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items : [Attachment 135533] Proposed patch
Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu> has asked Robert O'Callahan <roc@ocallahan.org> for superreview: Bug 112281: ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items http://bugzilla.mozilla.org/show_bug.cgi?id=112281 Attachment 135533: Proposed patch http://bugzilla.mozilla.org/attachment.cgi?id=135533&action=edit ------- Additional Comments from Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu> roc, what do you think? ...

SELECT from SELECT
Hi! I remember seeing an example where you can do a select from a nested select, but I cannot seem to make it work. So it would be something like this: select max( name ) from ( select name from customer union select name from vendor ) Was I dreaming I saw that? Thanks! D In article <4500243f@forums-2-dub>, daniel_AT_infrontsoftware_DOT_com@N0SPAM.com says... > Hi! > > I remember seeing an example where you can do a select from a nested > select, but I cannot seem to make it work. No, you weren't. Try (UNTESTED!) adding a...

superreview granted: [Bug 112281] ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items : [Attachment 135533] Proposed patch
Robert O'Callahan <roc@ocallahan.org> has granted Boris Zbarsky (real world intrudes) <bz-vacation@mit.edu>'s request for superreview: Bug 112281: ctrl+shift+click whle making range selections in form <select> shouldn't wipe out other selected items http://bugzilla.mozilla.org/show_bug.cgi?id=112281 Attachment 135533: Proposed patch http://bugzilla.mozilla.org/attachment.cgi?id=135533&action=edit ------- Additional Comments from Robert O'Callahan <roc@ocallahan.org> looks quite straighforward :-) ...

CheckBoxList doesn't show selected values on Postback
Hey everyone, I have a CBL that's databound using a datatable.  However, when I try to iterate through the selected values, it always shows that nothing it selected.  Here's where's I get the what's been checked:1 if (IsPostBack) 2 { 3 Response.Write("Checked values: "); 4 for (int i = 0; i < cblProducts.Items.Count; i++) 5 { 6 if (cblProducts.Items[i].Selected) 7 { Response.Write(cblProducts.Items[i].Text); } 8 } 9 } Here's the aspx: <...

Form: Focus on selected values in dropdownlists, Refresh after selection and hidding formfields based on selection.
Hello again,I have a form with several dropdown lists. Depending on the selected value in the dropdown lists other fields become available in that same form. It is working in classic ASP in combination of JavaScript. I want to migrate it to ASP.NET. I have posted a part of the form at the end of this post.My questions:1. I use <option <%If iFood="0" then%>selected<%End If%> value="0">No value selected</OPTION> to select the selected item when the form is reloaded after the selecting. I know that this also works in ASP.NET, but isn't there a typical ASP....

ddl in user control doesn't show selected value when redirected to another webform
i have a user control as  header in my webform.i have included a ddl to select the value of cp(variable in my application) in the header user control. when the user selects an item in the ddl , i redirect that  value using response.redirect("webform1.aspx" & strquery) from the user control code  to webform1..Webform1 is where i've placed the header.... i've written the code to fill the cp ddl from the database.now i select a value from the ddl, the value is redirected and can be displayed. however, the selected value does not appear as selected in the ddl. how to...

dynamically populating a select box depending upon selections in another select box
Dear sir, I am trying to populate a select box depending on multiple selections in another select box. I find the dependent select box does not populate at all. while it does populate if the parent select box is a single election box and not multiple. i want to use javascript so that for population i do not have to go to the server. I am using onchange event to execute the function.  Some one please help. pcg Could you post your code?jameswrightwww.jwright.info"Never be so busy making a living that you forget to make a life." Relevent code is given below please. Pa...

superreview requested: [Bug 244761] Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected : [Attachment 149378] Change the check for if the dropdown is show
Doron Rosenberg (IBM) <doronr@us.ibm.com> has asked Robert O'Callahan <roc@ocallahan.org> for superreview: Bug 244761: Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected http://bugzilla.mozilla.org/show_bug.cgi?id=244761 Attachment 149378: Change the check for if the dropdown is shown to the correct way http://bugzilla.mozilla.org/attachment.cgi?id=149378&action=edit ...

superreview cancelled: [Bug 244761] Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected : [Attachment 149378] Change the check for if the dropdown is show
Simon Paquet (back in business) <bugzilla@babylonsounds.com> has cancelled Doron Rosenberg (IBM) <doronr@us.ibm.com>'s request for superreview: Bug 244761: Pressing Esc while on <select> that's not dropped down shouldn't change which option is selected http://bugzilla.mozilla.org/show_bug.cgi?id=244761 Attachment 149378: Change the check for if the dropdown is shown to the correct way http://bugzilla.mozilla.org/attachment.cgi?id=149378&action=edit ------- Additional Comments from Simon Paquet (back in business) <bugzilla@babylonsounds.com> ...

superreview requested: [Bug 269561] Dropup/dropdown boxes leave gray box visible after selection if <select> has height/width on Mac : [Attachment 171565] Don't set mVisible to true willy-nilly
Simon Fraser <sfraser_bugs@smfr.org> has asked Boris Zbarsky <bzbarsky@mit.edu> for superreview: Bug 269561: Dropup/dropdown boxes leave gray box visible after selection if <select> has height/width on Mac https://bugzilla.mozilla.org/show_bug.cgi?id=269561 Attachment 171565: Don't set mVisible to true willy-nilly https://bugzilla.mozilla.org/attachment.cgi?id=171565&action=edit ...

superreview granted: [Bug 269561] Dropup/dropdown boxes leave gray box visible after selection if <select> has height/width on Mac : [Attachment 171565] Don't set mVisible to true willy-nilly
Boris Zbarsky <bzbarsky@mit.edu> has granted Simon Fraser <sfraser_bugs@smfr.org>'s request for superreview: Bug 269561: Dropup/dropdown boxes leave gray box visible after selection if <select> has height/width on Mac https://bugzilla.mozilla.org/show_bug.cgi?id=269561 Attachment 171565: Don't set mVisible to true willy-nilly https://bugzilla.mozilla.org/attachment.cgi?id=171565&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> sr=bzbarsky ...

First gridview's selected row doesn't update second gridview's objectdatasource
 HelloI got 2 gridviews on a page, each with its own ObjectDataSource. The first gridview fills itself just normally, no problem there. The second gridview needs to fill itself with other data, where the primary key is the primary key of the selected row of the first gridview.schematically:gridview1 row: IDfield, x, y, zrow: IDfield, x, y, z (-> this row is selected)row: IDfield, x, y, z gridview2 row:IDfield_of_selected_row_in_gridview1, a, b, c I tried to do this by configuring the ObjectDataSource behind gridview2 with a parameter pointing to gridview1.selectedValue. (by usin...

Web resources about - Second SELECT-box doesn't show the selected value as SELECTED - asp.net.web-forms

Resources last updated: 12/13/2015 12:14:44 PM