views:

113

answers:

2

This is related to Classic ASP code. A page fetches data for a particular ProjectCode.

There is a general text field which shows the Site-Location for selected Project-Code. I want to change it to drop down, so that a user can change the Site-Location from options available (fetched from DB) and then save it. Also, on page load the Site-Location of Project-Code for that particular entry should be selected.

I have added following code to my Page, but it doesn't work(definately I am new to classic ASP).

    strSQL = "SP_GET_SiteLocation"
    Set rsSiteList = RunSQLQuery(strSQL)

    'show the list
    If Not rsSiteList.EOF Then
    Do While NOT rs.EOF
    SiteLocationList= SiteLocationList & "<option value="">" & rs("LOCATION") & "</option>"
    rs.MoveNext 

Also, on click of save button, i have to send the selected drop down value to update query.

+1  A: 
Gaby
@RMN, updated answer.. (*you never write the options in the page*)
Gaby
Thanks Gaby. Seems i am getting closer to it. I do not want to add the fields as static value. "Location" is the Value i am getting from Stored proc which i need in drop down.I added response.write(SiteLocationList) just above rsSiteList.MoveNext and it showd me 3 entries in drop down, rest all in a line outside dropdown.Also i want the value selected in <%=rsReqDetails("AppReqSiteID")%> as the default selection in the drop down.
RMN
@RMN, do not print the SiteLocationList from inside the loop, because you are adding the options to it, so each time you print it, it will print all the options again increased by one.. Also, what is the `<%=rsReqDetails("AppReqSiteID")%>` ? another recordset ? and that value should be checked with what ? does your `rsSiteList` recordset have id values as well somewhere ?
Gaby
Yes, it is another recordset and no, rsSiteList has no Id, it has only values("Location"). Now the scenario is something like: For a Project-ID '122' I have details in recordset "rsReqDetails". The "AppReqSiteID" for Project 122 is "Two". I want the dropdown to show "One","Two","Three" ... and by default "Two" should be selected. This dropdown is what right now we are trying to fix. Also if i change the selection to "One", it should save changes in database on click of Save button.
RMN
Ok, Now i can see the Drop down and the values in it, but how do I display the selected value(that is value in: <%=rsReqDetails("AppReqSiteID")%> ) as default selection in this dropdown.
RMN
@Nimesh, are you sure that the `rsReqDetails("AppReqSiteID")` is equal to one of the `rsSiteList("LOCATION")` ? because the example above should select it if it finds it ..
Gaby
Yes, for all the entries it shows the first location from dropdown.
RMN
And not Nimesh.. :) rmn .. :)
RMN
Gaby, i am still not able to see the required selection. Only first option from the dropdown list is default selected.
RMN
@RMN, can you please add cahnge the `<select id="SiteLocationList" NAME="SiteLocationList">` to `<select id="SiteLocationList" NAME="SiteLocationList" value="<%=selectedValue%>">` and post here the rendered result (*view source and show us what is there..*)
Gaby
Ok, that is a silly mistake of mine :( i referenced Location in stored proc where as it should have been Site. Thanks for the last comment, it helped me find this out.Thanks a lot for all your help in solving this issue.
RMN
A: 

You almost got it, you're missing the "select" tag:

    strSQL = "SP_GET_SiteLocation"  
Set rsSiteList = RunSQLQuery(strSQL)  

'show the list  
If Not rsSiteList.EOF Then  %>
<select><%Do While NOT rs.EOF SiteLocationList= SiteLocationList & "<option value="">" & rs("LOCATION") & "</option>"  
rs.MoveNext %>
</select>
Andrea
Yes, this displays the drop-down, but empty dropdown :(
RMN