|
With the FrontPage Database
Results Wizard, you could do Insert / Database Results click your way along, and at some point
choose input parameters that a user would submit on a search form, and the Wizard would create the search form for you automatically. You
didn't have to know or understand how the form passed the information to the database results.
To accomplish the equivalent using Expression and its ASP.NET controls:
First make two separate pages, one called search.aspx where we will put the search form, and another called
results.aspx where we will display data from a database using the
parameters inputted by the user on the search page.
Open the search.aspx page. Being an aspx page, it already has a form on it. In Design View drag a TextBox Control on to the form (ASP.NET Controls / Standard / TextBox). This will be the field a user enters their search term into.
Give the form field a useful name by selecting the form field, going to the Tag Properties and changing the value of ID to a meaningful name, for example "LastName". You would use
such a name if later on the Results.aspx page you wanted to show the results of a search based on
someone's last name in the database (and, of course, the database needs to
have "LastName" as a field in each record).
You need a submit button for the form so Drag a Button onto the form (ASP.NET Controls / Standard / Button). Select the Button, go to Tag Properties and change the Text attribute of the button to a meaningful name such as "DoTheSearch"
Under Behavior, set the value of PostBackURL to Results.aspx. This will cause the value entered by a user into the textbox to become the imput parameter for the search results on the Results.aspx page
Save the page and now open the Results.aspx page
In Design View, drag a GridView onto the page.
Click on the little arrow in the upper right of the GridView and select Configure Data Source Choose the database that the user will be searching and select the fields you want to show in the GridView results (you can select all the fields by checking the column with the asterisk).
Now here is the important part. Click the WHERE button. 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, then select the LastName field.
Leave the Operator set at "=" for this particular search. Then a key thing is to choose "Form" as the Source, and type the name of your search form field on the search.aspx page (remember we named the text field on the search form "LastName") in the Parameter Properties Form field box.
Click Add, OK, Next, TestQuery, OK, Finish.
Save the page and close it.
Open search.aspx, preview in browser, and test your search.
You now have accomplished all you could have accomplished with the FrontPage
Database Results Wizard.
Tutorials
Home
|