Searching with only one search parameter (ASP.NET)
When the user clicks the pages Search button, the search parameter is sent to the server. The server processes the request, builds a filtered DataSet based on the parameter, populates a DataGrid, and sends the page back to the browser.
Before adding the DataGrid, you must define a DataSet that finds and stores all the records that meet the search criteria.
To create a DataSet to hold the search results:
- In the Bindings panel (Window > Bindings), click the Plus (+) button and select DataSet (Query).
If the advanced dialog box appears, click the Simple button to open the simple dialog box.
- Name the DataSet, and then select a connection and database table containing the data you want users to search.
- In the Columns area, click the Selected option and select a key column (usually the record ID column) and the columns containing the data you want to display in the DataGrid.
Leave the DataSet dialog box open for now. Youll use it next to retrieve the search parameters sent to the server and create a DataSet filter to exclude records that dont meet the parameters.
To create a DataSet filter:
- From the first pop-up menu in the Filter area, select a column in the table to compare against the search parameter sent by the search page.
For example, if the value sent by the search page is a city name, select the column in your table that contains city names.
- From the pop-up menu beside the first menu, select the equal sign (it should be the default).
This choice states that the user wants only those records in which the selected table column is exactly the same as the one specified on the search page. You can use a less restrictive option such as "begins with" or "contains."
- From the third pop-up menu, select Form Variable.
The parameter is sent to the server by a form using the POST method.
- In the fourth text box, enter the name of the form control that sent the search parameter to the server.
You can get the name by clicking the form control on the form to select it, and checking the controls ID in the Property inspector.
- If you want, click Test, enter a test value, and click OK to connect to the database and create an instance of the DataSet.
The test value simulates the value that would otherwise have been returned from the search page. Click OK to close the Dataset.
- If youre satisfied with the DataSet, click OK.
Dreamweaver inserts code in your page that, when run on the server, checks each record in the database table. If the specified field in a record meets the filtering condition, the record is included in a DataSet. The code in effect builds a recordset containing only the search results.
The next step in creating the search page is to display the search results in a DataGrid. See Displaying the results in a DataGrid.