Adding Dynamic Capabilities
In this part, we are going to add code to dynamically set the number of records to display, and to add search capability.To dynamically set the number of records to display, just above the Prev and Next buttons, add the code shown below.Number of Records to Show:
onchange="tblElements.dataPageSize = this.value;"><br>Note: With a database this small, this feature might get confusing because when you browse to the beginning or end of the database, it can only show the number of rows remaining, which is likely to be less than the number of records you set it to display.To add a search capability, just below the Prev and Next buttons, add the code shown below.Enter Filter Parameters:
onchange="ebaydb.Filter = this.value; ebaydb.Reset();">This creates a text box where you can type in a "filter". For example, if you enter Cost = 8.50 in the text box and click on theNext button, The web page will display the record for the Action Figure because that is the only item in the database with a cost of 8.50.
If you enter Desc = Video Game in the text box and click on theNext button, the web page will display the record for the Video Game.
If you enter Item > 10002 in the text box and click on the Nextbutton, the webpage will display SOME of the records where Item is greater than 10002. We know there are 14 records in the database where Item is greater than 10002, but the webpage will only display the number of records you set it to display. To see more of the records in the database where Item is greater than 10002, you have to click the "Next" button.
If you enter Cost >= 5.00 & Cost <= 10.00 the web page will display the records where the Cost is between 5.00 and 10.00. See if you can come up with some filters on your own.
Below is the entire code, up to this point, for the Notepad Database (excluding the "comma delimited values" database itself).
After adding this code, open the webpage in Internet Explorer to verify that the table header appears correctly. I will give you the code to make the Cost column click sortable, from which you should easily be able to figure out the code to make the other columns sortable.
First you have to add an onclick event handler to the span with id="Cost" as shown below.
<td><span id="Cost" onClick="sortCost()">Cost</span></td>
Note that the onclick event handler calls a function named sortCost. The code for that function is shown below.
ebaydb.Sort = "Cost";
Add this code to the Java Script code block in the head of the webpage,
One last thing. The Cost column will not sort correctly because we didn't define it as a float in our comma delimited values (CDV) database file. This is a simple and quick modification. Just open the database file ebay.txt and edit the first line as shown below, adding the :FLOAT next to Cost. If you don't do that, the Data Source Object (DSO) defauts the field to "string".
If you intend to make all the columns click sortable, you can specify the data types of all the fields right now as shown below.
Using Images in Your Database
Lets review. To enable a databse to bind to html elements on a web page, we used the <object> tag to a Data Source Object (DSO) called the Tabular Data Control (TDC) on the webpage. In Internet Explorer 4.0 and higher, Microsoft added special attributes to html elements to make data binding possibe. The <table> tag uses the datasrc attribute to specify the DSO that the table should bind to. It uses the dataPageSize attribute to specify the maximum number of records to diaplay at once.
The Table data tag <td> uses the dataFld attribute to specify which field in a record to bind to. It uses the dataFormatAsattribute to specify how the data is to be rendered. In this article we used the default format text.
Another format is html. Just imagine how powerful this is. Your database could contain html and that html will be rendered. To say it another way - you can have webpages in your database. For example, the "text" in a field of your database could the html for a link or for an image tag. below is an example of a link or for an image tag.
<tr><td><span datafld="Image" dataformatas="html">
Below is a screen shot of a database application based on the code used in this article. This could be used as a photograph library, an inventory with photographs, or a catalog database.
In this article, we created a database using Notepad that consists of comma delimited values (CDV). The only thing we need to use the database is Internet Explorer. We placed a Data Source Object (DSO) called the Tabular Data Control (TDC) on the webpage. In Internet Explorer 4.0 and higher, Microsoft added special attributes to html elements to make data binding possibe. We used these attributes to browse, search, and sort the database.
To make learning easier, I kept the code to bare bones. You should understand the code enough to create a database to organize your DVD collection, your checkbook, personal contacts or club members, or any other data. With a little extra html code, you should be able to make a much nicer webpage to display the database.
For your convenience I have provided all of the files for the ebay database and the image database in a zip file. Click here to download the example files.