% option explicit %>
<!-- #INCLUDE FILE="./adovbs.inc" --> <!-- #INCLUDE FILE="DbPath.inc" --> <% 'DbPath.inc is used to establish database connection 'copy and paste the source code , save this as wsdx-category.asp Dim strCategory strCategory=Request("cboCategory") Set Rs = Server.CreateObject("ADODB.Recordset") Rs.ActiveConnection = OBJdbConnection Rs.Source = "SELECT * FROM tblProduct WHERE productCategory ='" & strCategory & "';" Rs.Open 'this is added to check whether a record is found 'if there is no record then when first open, Rs.EOF will be true If Rs.EOF then Response.Write("Items not found") Else Response.Write("<table border='1'><tr><th>Product Name</th><th>Manufacturer</th><th>Price</th><th>Category</th></tr>") Do Until Rs.EOF Response.Write("<tr><td>" & Rs("productName") & "</td><td>" & Rs("manufacturer") & "</td><td>" & Rs("price") & "</td><td>" & Rs("productCategory") & "</td></tr>") Rs.MoveNext Loop Response.Write("</table>") End if Rs.Close Set Rs= Nothing %> <h3>Search by category</h3> <form name="frmSearchCategory" action="wsdx-category.asp method="post"> <table> <tr><td>Choose a category:</td> <td><select name="cboCategory" style="width:100px"> <option value="Strategy">Strategy</option> <option value="Action">Action</option> </select></td> <td><input type="submit" value="Search" /></td></tr> </table> </form> <% 'this is to set the combo box value to be what has been chosen before the search Response.Write("<script>frmSearchCategory.cboCategory.value='" & strCategory & "'</script>") %>