If you're reading this section, it's safe to say that you're either curious about learning how to develop .NET applications in Dreamweaver or you're simply broadening your knowledge of the extensive functionality available in Dreamweaver.
When I first starting using UltraDev years back, I was amazed at the simplicity between the program and the various server models that existed at the time. When I first started beta testing Visual Studio.NET and ASP.NET in 2000, I wondered whether Macromedia would ever include the power of DataSets, DataGrids, and DataLists into its newest version of Dreamweaverand if they did, how they would go about doing it. As it turns out, Macromedia answered my questions by incorporating the easy-to-use functionality of the ASP, ColdFusion, and PHP server models with the power of the ASP.NET server model.
If you've read the previous sections, most of this will be a review. What this section covers differently however, is an overview of the power exposed via DataSets, DataLists, DataGrids, and the ASP.NET application development capabilities using Dreamweaver. Specifically, this section covers the following topics:
DataSets
Paging
Dynamic text (object binding)
Region repeaters
Showing specific regions (conditionals)
DataGrids
DataLists
If you are familiar with traditional data storage and retrieval models in ASP, you are familiar with the recordset. The recordset acts as a virtual table to store information retrieved from the database. In Dreamweaver, DataSets are similar to recordsets.
NOTE
Dreamweaver uses DataSets as the storage mechanism for your data when working with ASP.NET. It's important to note that, unlike a recordset in ASP which only represents one table (even if you've created joins, one virtual table is still represented in the recordset) from your data source, a DataSet can contain multiple tables, known as DataTables. DataReaderswhich are not covered within the context of this bookare similar in nature to traditional recordsets in that they support only one table from your data source.
To better understand DataSets is to better understand ADO.NET. ADO.NET is a set of namespaces and classes that provide access to data stores. Three layers make up ADO.NET:
The Data Store : The data store represents the physical location of your data. This can be a relational database (Access/MSDE/SQL Server 2000) or an XML file.
The Data Provider : The data provider connects the data store and the DataSet, filling the DataSet with data from the data store and synchronizing changes made to the DataSet with the data store.
The DataSet : The DataSet is the container for your data and the relationships that make up your data.
Now that you know the basic makeup of ADO.NET, you can begin to plug in all the different aspects that make up your application. Your data store consists of an OLE DB database in Access. Earlier in this chapter, you learned how to create a connection using the ASP.NET server model. Now let's jump into creating the commands and working with DataSets. To begin creating a DataSet, follow these steps:
1. | Begin by opening the employeestore.aspx file located in your Site Files list. |
2. | To create a DataSet, select the DataSet (Query) option from the Add (+) menu in the Bindings panel. The DataSet dialog appears. |
3. | In the DataSet dialog, enter the name dsEmployeeStore in the Name text box. |
4. | Select the connDorknozzle option from the Connection drop-down menu. |
5. | Choose the EmployeeStore table from the Table drop-down menu. |
6. | Make sure that the All radio button is selected in the Columns radio button group. When you finish making your changes, the dialog should resemble Figure 25.40. Figure 25.40. Configure options for your DataSet in the DataSet dialog. |
7. | Test the DataSet by clicking the Test button. Figure 25.41 displays the results that you should also be seeing. Figure 25.41. Testing the DataSet returns the complete list of items. |
8. | Click OK to close the Test SQL Statement dialog. |
9. | Click OK to close the DataSet dialog. The new DataSet is created. |
You can view all the fields in the DataSet by expanding the dsEmployeeStore DataSet from the Bindings panel. Figure 25.42 shows the results of expanding the DataSet nodes.
Creating a Recordset from a View," earlier in this chapter.
Now that you have a DataSet clearly defined, your next step is to get the information out of the DataSet and into your application. Dreamweaver's Server Behavior and Binding panels provide the functionality you need to get started producing dynamic elements that are centralized within the database but exposed by the application. Let's get started!
The first step to creating dynamic applications is to make all your text as dynamic as possible. That is, to allow all your company's valuable information to reside in the database and then pull it out onto dynamic pages as needed. To start creating dynamic text, begin by creating a table that organizes the data output. You can accomplish this by following these steps:
1. | Replace the text INSERT TEXT HERE in the employeestore.aspx page with a new table by selecting Insert, Table. This table should have one row, two columns, a width of 460, and 0 for border thickness, cell padding, and cell spacing. Click OK after you have entered these values. |
2. | Insert a nested table in the cell on the right. Give this nested table 3 rows, 1 column, a width of 300, and 0 for border thickness, cell padding, and cell spacing. |
3. | Add the text Name, Description , and Cost in the three rows for the table you just created. You might decide to make the text bold so that it stands out to the user. The result appears similar to Figure 25.43. Figure 25.43. Place static text in the three fields to caption the dynamic text. |
4. | Expand the dsEmployeeStore DataSet in the Bindings panel to reveal all the fields in the DataSet. |
5. | Manually click, hold, and drag the ItemName field from the dsEmployeeStore DataSet in the Bindings panel into the cell for the table you just created, making sure that you drop the field just next to the Name caption. |
6. | Repeat step 5 to drag the ItemDescription and Cost fields into their proper cells next to the Description and Cost captions. The result resembles Figure 25.44. Figure 25.44. Drag the remaining fields into their respective locations. |
Save the page and display it in the browser by pressing F12. You're probably noticing that the browser is giving you an error. The problem here is two fold: First, Dreamweaver stores connection information in a file known as Web.Config (you've probably noticed this file in the root of your directory). Under the ASP.NET server model, Web.Config files are used for global application settings (such as storing connection strings). In this case, because we have a Web.Config file in the root directory, the browser throws an error expecting the directory to be defined as an application within IIS, which at this point it's not. Second, Dreamweaver uses a precompiled assembly called DreamweaverCtrls.dll for implementing features such as DataSets.
For our page to run under ASP.NET, the DreamweaverCtrls.dll file must be deployed into a Bin folder in the root of our application. At this point, the DreamweaverCtrls.dll file hasn't been deployed so let's do it now:
1. | Switch to the Components tab (the fourth tab in the Application panel group). |
2. | Click the small Deploy icon (represented by the Up arrow). Dreamweaver presents the Deploy Supporting Files to Testing Server dialog. |
3. | Type the path to the Bin folder as follows: C:\Inetpub\wwwroot\DorknozzleASPX\Bin . Alternatively, click the folder icon to browser for the specific folder. If the Bin folder doesn't exist in the DorknozzleASPX folder, you must create it now. |
4. | Click the Deploy button. |
5. | An alert message indicating that the file has been deployed is shown. Click OK. |
Next, we'll need to convert the project into an application within IIS. To do this, follow these steps:
1. | Open IIS by choosing Start, Settings, Control Panel, Administrative Tools, Internet Information Services. |
2. | Expand all the tree nodes until all your sites are listed under the Default Web Site node. |
3. | Right-click the DorknozzleASPX folder and select the Properties option from the context menu. The DorknozzleASPX Properties dialog appears. |
4. | Click the Create button in the Directory tab. That's it! You've just turned your project into an application in IIS, and you've successfully deployed the necessary files to work with ASP.NET. Fortunately, this is the last time you'll have to run through this process. |
5. | Click OK to close the dialog. |
6. | Close IIS and return to Dreamweaver. |
Now try running the page again by pressing the F12 key. As you can see from Figure 25.45, the first item in our EmployeeStore table is shown on the page.
Congratulations! You've just taken your first step to working with dynamic web pages in ASP.NET! As the ASP.NET sections unfold, you'll learn to add dynamic images, repeating regions, pagination functionality, and more. This is just the tip of the iceberg.
Now that you've created dynamic text within your ASP.NET application, you're ready to begin adding dynamic images. The images we will add here are not the typical static images we have used throughout the book; instead, they will be dynamic images. Recall that we added the path to the image associated with each item to the EmployeeStore table. What we want to do now is dynamically show the image, based on the path outlined within the ImageURL field, on our dynamic employeestore.aspx web page. To do this, follow these steps:
1. | Place your cursor in the cell designated for the image (the left most cell) and vertically align the cursor to the top of the cell by choosing the Top option from the Vert menu in the Properties Inspector. |
2. | Select the Image option from the Insert menu. The Select Image Source dialog will appear. |
3. | Near the top of the Select Image Source dialog box, you have options for selecting the image from the File system (static) or you can choose the Data sources option (dynamic). Select the Data sources option. The Select Image Source dialog box's interface will immediately change to allow you to select an image path from the DataSet. Select the ImageURL field shown in Figure 25.46. Figure 25.46. Insert an image dynamically by adding it from a data source rather than from the file system. |
4. | Select OK. The dynamic image placeholder will appear within the cell. |
Save your work and test the results in the browser by choosing the F12 key. The image for the Dorknozzle T-Shirt should now appear as shown in Figure 25.47.
Now that you've seen just how easy it is to place dynamic content on the page, you'll probably want to begin adding features such as paging that allow users to interact with the content. Paging exposes all records (or certain sets of records) within a pagination system, not unlike those of a book. For every press of a button, your user can advance to the next set of records or, conversely, return to a previous set of records. Dreamweaver's pagination behaviors include the following:
Move to First Page : Returns the user to the first page in the DataSet.
Move to Previous Page : Returns the user back one page.
Move to Next Page : Advances the user one page forward.
Move to Last Page : Advances the user to the last page in the DataSet.
To begin adding pagination features to your site, follow these steps:
1. | Place your cursor just below the table that includes the dynamic data. |
2. | From the DataSet Paging submenu, available by clicking the Add (+) button in the Server Behaviors panel, select Move to Previous Page. |
3. | The Move To Previous Page dialog appears, similar to Figure 25.48. Select the Create New Link: "Previous" option from the Link menu and make sure that the dsEmployeeStore DataSet is selected from the DataSet menu. Click OK. A new dynamic Previous hyperlink is created. Figure 25.48. Confirm the settings from the Move To Previous Record dialog. |
4. | Add a space after the Previous hyperlink and repeat steps 2 and 3, this time selecting the Move to Next Page option from the DataSet Paging submenu. When you're finished adding the complete pagination functionality, two hyperlinks, one identified as Previous and one as Next should appear underneath the table similar to Figure 25.49. Figure 25.49. Dynamic Previous and Next hyperlinks will appear under the table that contains the dynamic image and text. |
Save your work. If you've tested the results in the browser you might be wondering why the paging widgets aren't working. Like the ColdFusion model, the ASP.NET server model expects the Repeat Region server behavior to be added before the Paging behavior will work. Let's do that next.
Although DataSet paging is the ideal model to strive for, at times you might want to display all the records (or groups of records) in the database at once. The Repeat Region behavior enables you to create a pattern of repeatable instances within your application. For instance, in the EmployeeStore example, a table was created to display the content for the image, name, description, and cost. Using the Repeat Region server behavior, you are able to maintain that structure while repeating the contents for every record contained within the dsEmployeeStore DataSet throughout the page. To create a repeatable region, follow these steps:
1. | Select the table for which you want the content to repeat for. Your selection should resemble Figure 25.50. Figure 25.50. Select the table that you want to create the repeatable region for. |
2. | Select the Repeat Region option by clicking the Add (+) button within the Server Behaviors panel. The Repeat Region dialog box will appear similar to Figure 25.51. Figure 25.51. Display five records at a time from the dsEmployeeStore DataSet in the Repeat Region dialog. |
3. | The Repeat Region dialog box enables you to enter choices regarding which DataSet to create the repeat region for as well as how many results to display. Make sure the dsEmployeeStore option is selected from within the DataSet menu. Additionally, make sure 5 Records at a Time is selected. Click OK to apply the server behavior to the selected table. |
Save your work and test the results within the browser by selecting the F12 key. Notice how you can scroll down the page to view five Dorknozzle products at a time. More importantly, try clicking the Next hyperlink. As you can see, the paging server behaviors now work.
As you allow users to cycle through your records, you might find that eventually you'll want to display some sort of message letting the user know what record they are currently viewing. This can be accomplished by simply displaying a numerical value for the record they've cycled to somewhere on the page. Dreamweaver includes a set of behaviors that enable you to do just that; they are known as the Display Record Count server behaviors, and there are four of them:
Display Starting Record Number : Displays the first record number of the DataSet.
Display Ending Record Number : Displays the last record number of the DataSet.
Display Total Records : Displays all the records of the DataSet.
Display Current Page Number : Displays the current page number in the DataSet. This number changes as the user pages through the records.
Like all the other behaviors you have been working with, the Display Record Count behaviors can be inserted into your application very easily. To insert the Display Current Page Number behavior into the employeestore.aspx page, follow these steps:
1. | Place your cursor somewhere on the page where the user is most likely to look for a record count. A good place is somewhere near the paging navigation bar at the bottom of the page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2. | Type the text Page Number: . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3. | Select the Display Current Page Number behavior from the Display Record Count submenu in the Add (+) menu in the Server Behaviors panel. The Display Current Page Number dialog appears. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4. | Select the dsEmployeeStore option from the DataSet menu and click OK. A Dynamic Current Page element appears next to the paging navigation menu.
Save your work and test the results in the browser by pressing the F12 key. Click the Next and Previous links to page through the records, watching the counter update dynamically (see Figure 25.52). Figure 25.52. The current page number appears near the bottom of the page.Showing Specific RegionsNow that you've added the capability to cycle to the end of the DataSet and back, consider the following problem: Users click Next until they get to the last record and then they're abruptly stopped. They keep clicking the Next button but nothing happens. The problem is that the user has reached the end of the DataSet and they can't go any further because there's no data left in the DataSet. Unfortunately, the user doesn't know that. Instead, it might serve you and your users better if you alerted them of the fact that they've reached the end of the DataSet. To accomplish this, Dreamweaver provides functionality in the form of a group of Show Region behaviors that alerts users that they have reached the end of the DataSet. The complete list of Show Region behaviors are as follows:
To add a Show Region behavior to your application, follow these steps:
Save the page and test the results in the browser. You'll notice that the message will only appear when you reach the last page of records in the DataSet. Working with DataGridsOne of the most important and feature-rich controls included with Dreamweaver's ASP.NET integration is the DataGrid control. The DataGrid control, similar to the Repeat Region behavior and the DataSet Paging behaviors, enables you to display numerous records on the page while allowing pagination functionality. For instance, you could display every five records within the DataSet while allowing paging to the next set of five records. In a footer on the page, you could display a list of numbers that correspond with every group of five records to display. As the user selects a new number, a new group of records is displayed. The DataGrid's flexibility does not end there; DataGrids also allow for column sorting, editing, and even custom commands. Some of the column types available with the DataGrid control are listed here:
Now that you know what a DataGrid is, let's create a simple DataGrid for the EmployeeStore Web page. To add the DataGrid, follow these steps:
Now save your work and test the result in the browser by pressing the F12 key. Figure 25.55 shows the results of what the DataGrid will look like after it is complete. Notice that paging functionality is automatically added for you in the footer of the DataGrid. Figure 25.55. The browser shows the result of the DataGrid.Also notice that the column headers, alternating rows, and backgrounds have prespecified colors. Although the color scheme Macromedia chooses to use as a default is fairly tasteful, it does not match the color scheme of the Dorknozzle site. To change the color scheme of the DataGrid, follow these steps:
Save your work and test the results in the browser by pressing the F12 key. Notice that the new color scheme of the DataGrid matches the color scheme of the Dorknozzle site. Using Hyperlinked Columns to Create Master/Detail PagesAs mentioned earlier, column types can be changed to different types, depending on what you are trying to accomplish. One of the several column types is that of a hyperlink. A hyperlinked column type allows the items that reside in a column within a DataGrid to be hyperlinked to a different page. A good use for this feature is for creating master/detail pages. Master/detail pages enable you to show brief information for a specific item; when users want to see more detailed information, they select the link for a particular product and are linked to a page that contains more descriptive information for that product. To create a master/detail relationship using a hyperlinked column, follow these steps:
Save your work and test the results in the browser by pressing the F12 key. The result should look similar to Figure 25.58. Figure 25.58. All the item names are now linked and ready to navigate to their appropriate page.Notice that the names in the ItemName column are now clickable. Roll your cursor over the product name. As you do, look in the status bar to see that the link and correct product ID are displayed. Next, let's create the employeestore_datagrid_details.aspx page:
|