Create a Database Search Page Using Expression Web
Authors: Clark Kurtz (A.K.A Homepage Doctor) and Anna Ullrich
The old FrontPage method
With the Database Results Wizard in FrontPage, you could select Insert > Database > Results and then click your way along, choosing fields that a user would submit on a search form, and the Database Results Wizard would automatically create the search form for you. You didn't have to know or understand how the form passed the information to the database and generated search results.
The new method in Expression Web
The old FrontPage method was certainly simple, but you will find that using the ASP.NET controls in Expression Web is just as simple, plus you will gain a lot with the new technique. For example, with Expression Web you can integrate the membership and login features of ASP.NET with your database to enable users to manage their own information—something that could not be not be accomplished at all with FrontPage.
What you’ll need
For this tutorial, you will need an Access 2003 database with the file extension *.mdb. (You can also use SQL databases, sitemap files, and XML files as data sources in Expression Web but for the purposes of this tutorial we’re using an Access 2003 database.) If you don’t have an Access 2003 database, you can download a database template from the Microsoft Office Online website to get you started:
For this tutorial, the best fit is probably the “Sales contact management database” here:
And if you don’t have Microsoft Office Access, you can download a trial version of the 2007 program, which is able to work with Access 2003 databases:
And last but not least, if you don’t already have Expression Web, you can download a trial version here:
How to create database search and search results pages with Expression Web
- In Expression Web, open an existing website or create a new website. If your website does not already contain your database file, choose File > Import > File, click Add File to select your database file, and then click OK to import it.
- Create two separate ASPX pages. Name one of the pages search.aspx, which is where we will put the search form. Name the second page results.aspx , which is where we will display the search results.
- Open the search.aspx page; being an ASPX page, it already has a form on it. The following screenshot is the Split view of the search.aspx page, showing the source code at the top and the Design view at the bottom.
- In the Toolbox task pane, expand the ASP.NET and Standard categories and drag the TextBox control into the form on your page. This TextBox control will be the field your site visitors use to enter their search terms.
- To give the TextBox control a useful name, select the TextBox control in your page, go to the Tag Properties task pane, and then change the value of the ID property to a meaningful name. In this example, the TextBox control was given an ID of “LastName” (without spaces) since that is the name of the database field we are planning for our site visitors to search on.
- You need a submit button for the form so go to the Toolbox task pane and drag a Button control from the ASP.NET Controls > Standard category onto your form.
- Select the Button in your form, go to the Tag Properties task pane, and then change the Text property of the button to a meaningful name such as "Do The Search”. (The text you enter is displayed on the button in the web page.)
- Next, set the value of the button’s PostBackURL property to results.aspx. The PostBackURL causes the text entered by the site visitor to become the input parameter for the search results on the results.aspx page.
- Save the search.aspx page.
- Open the results.aspx page.
- In the Toolbox task pane, expand the ASP.NET Controls > Data category, and drag a GridView control into the form in the Design view of your results.aspx page.
- Click the arrow button in the upper right corner of the GridView control in Design view, and in the GridView Tasks flyout click the drop down menu next to Choose Data Source, and select New data source.
- In the Data Source Configuration Wizard dialog box, select the type of database the user will be searching. For this example, we selected an Access Database, and accepted the default ID of “AccessDataSource1”.
Click OK, and then follow the onscreen instructions in the dialog box to select your database file. When you get to the Configure the Select Statement screen (see the next screenshot) go to the next step
- Under Columns, select the fields you want to show in the GridView results (you can select all the fields by checking the column with the asterisk). In the example, FirstName, LastName, CompanyName, and EmailName have been selected from the database. If you want to display all the fields, simply select the asterisk.
- And now here is the important part: Click the WHERE button to display the Add WHERE Clause dialog box.
- In the Add WHERE Clause dialog box, choose the field you want to search on from the Column dropdown list. This should be a field that is expecting the input text from the search form. For example, if your database listed FirstName, LastName, City, Phone, and you are trying to allow someone to search by last name, you would select the LastName field.
- Leave Operator set at "=".
- Set Source to "Form".
- Under Parameter Properties, for the Form field property, type the ID that you gave your search form field on the search.aspx page. (For example, we had named the text field "LastName" on the search.aspx page).
- Click Add.
- Then click OK, Next, TestQuery, OK, and then Finish.
- Save the page and close it.
- Open search.aspx in Expression Web, and then click the Preview in Browser button. This launches the Microsoft Expression Development Server which sends your page to your web browser, where you can test your search page.
Here’s how the search.aspx page looks in Internet Explorer 7:
And after entering “Philips” in the box and clicking the search button, the results.aspx page appears and displays these results: