I often encounter this when I make ASP programs:
The data in the database, such as all employee names, is listed in the list box, and the program requires that one or more of the items be selected for submission to the next page.
But the trouble is that if there is too much data (such as an employee), it can be a hassle for the customer's choice-to navigate from a long list of data. The best solution is the user in the choice of fuzzy query before the data positioning, accurate identification of the need to select the employee name, and then select, Submit.
The problem arises in front of our programmers: How to filter data from a database without refreshing the page filter. I have two kinds of methods:
1, the use of Double list box method
2. Using XML method
This article mainly introduces the first method: The method of using double list box
Programming Ideas:
Takes a double list box, one of which is hidden, and the other is a list box that is displayed to the user.
The program starts by loading data, such as employee names, into two list boxes, emptying the Display list box first when the user needs to filter the employee, and then loading the data from the hidden list box into the Display list box, based on the filter criteria.
This enables you to not refresh the content in the page filter database.
Realize:
The following is an example of SQL Server, which filters the employee name of the Employees table in the Northwind Library for instructions.
<title> do not refresh page Query method </title>
<metahttp-equiv= "Content-type" Content= "text/html;charset=gb2312"
<scriptlanguage= "JavaScript"
Functionsearch_onclick () {
file:// to filter employee's name
searchtext= Window.searchContent.value
file://first removes the option
J=searchobj.length in all query results lists;
for (i=j-1;i>=0;i--)
{
Searchobj.remove (i);
if (searchtext!= "") {
Option1.text=searchsource;
Option1.value=searchsource.options (i). value;
Searchobj.add (option1);
}
}
}
else{
file://such as fruit Show All employees
J=searchsource.len if no query criteria are entered Gth
for (i=0;i<j;i++) {
Searchsource=searchsource.options (i). Text
Option1=document.createelement ("option");
Option1.text=searchsource;
Option1.value=searchsource.options (i). value;
Searchobj.add (option1);
}
}
}
</script>
<bodybgcolor= "#FFFFFF" text= "#000000" >
<%
Servername= "wyb" ' Server name
user= "sa" user name
pw= "" ' User password
Databasename= "Northwind" database name
Setconn=server. CreateObject ("Adodb.connection")
Conn. Open "Driver=sqlserver; Server= "&servername&"; Uid= "&user&";p wd= "&pw&";D atabase= "& DatabaseName
Setrs=server. CreateObject ("Adodb.recordset")
Sql= "Selectemployeeid,lastnamefromemployeesorderbyemployeeid"
Rs. Opensql,conn%>
<tablewidth= "80%" border= "1" >
<tr>
<td>
<inputtype= "text" name= "Searchcontent" >
<inputtype= "button" name= "button" value= "Query" >
</td>
</tr>
<tr>
<td> Query Results <br>
<selectname= "Searchobj" size= "ten" >
<%dowhilenotrs.eof%>
<optionvalue= "<%=rs (" EmployeeID ")%>" ><%=rs ("LastName")%></option>
<%rs.movenext
Loop
%>
</select>
<selectname= "Searchsource" size= "ten" style= "Display:none" >
<%
Rs.movefirst
Dowhilenotrs.eof%>
<optionvalue= "<%=rs (" EmployeeID ")%>" ><%=rs ("LastName")%></option>
<%rs.movenext
Loop
%>
</select>
</td>
</tr>
</table>
<%rs.close
Setrs=nothing
%>
</body>