Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulate View State of Select Control

Status
Not open for further replies.

GoTerps88

Programmer
Apr 30, 2007
174
US
I am accustomed to ASP.NET's view state property for drop downs, etc.

Basically what I am trying to accomplish is this scenario. The select element is initially loaded with values via asp the first time the page loads.

Then when the user clicks a Requery button I would like to retain the value of the selected option in the select element and selecting that option. Right now it's refreshing everything.
 
Then when the user clicks a Requery button I would like to retain the value of the selected option in the select element and selecting that option. Right now it's refreshing everything.

Can you post your code? I'm not sure how you have things set up right now.

[monkey][snake] <.
 
Actually I figured it out from an earlier post where you provided a nice example.

The answer revolved around using the Request.Form(control) syntax to derive the value of the select control.

Code:
<%
	Dim scanYear
	If Request.Form("selYears") Then
	
		scanYear = Request.Form("selYears")
	Else
	
		scanYear = 2
		
	End If	
   
%>

In order to re-select the appropriate value in the select contol, I used this code.

Code:
<label for="selYears">Scan Year</label>
<select name="selYears" id="selYears">
<%

            Dim objRec
            Dim strSQLYears            

            strSQLYears = "someQuery"            

            Set objRec = Server.CreateObject("ADODB.RecordSet")
            objRec.Open strSQLYears,DataConn,0,1,1           

            Do Until objRec.EOF            
            

%>

            <% If Cint(objRec(0)) <> Cint(scanYear) Then %>
            <option value="<%= objRec(0) %>"><%= objRec(1) %></option>
            <% Else %>
            <option selected=true value="<%= objRec(0) %>"><%= objRec(1) %></option>
            <% End If %>

<%       

            objRec.MoveNext

            Loop            

            If objRec.State = 1 Then
                        objRec.Close
            End If  
%>   

</select>


Then later in the code I'm running a query based on the scanYear value. I just plug it in as a parameter.

Since you saved me some time with a previous post I'll give you a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top