After adding a DataGrid to the master page (see Creating the master page (ASP.NET)), you must create links that open the detail page and pass the ID of the record that the user selected. The detail page will use this ID to find the requested record in the database and display it.
The record ID is passed to the detail page in a URL parameter. For more information, see URL parameters.
In a DataGrid, you create these links by turning a column in the DataGrid into a hyperlink column and setting its attributes, as described in this section.
To open the dialog box, double-click your DataGrid in the Server Behaviors panel (Window > Server Behaviors).
The DataGrid dialog box opens.
The Hyperlink Column dialog box appears.
If you want to create a generic link such as Details for each row in the DataGrid, select the Static Text option and enter the text for the link. Each row in the DataGrid will display the same text (such as Details) in the hyperlink column.
If you want to add links to data displayed in the column, select the Data Field option and select a data field in your DataSet. The data field provides the text for the links in your hyperlink column. In the following example, each row in the DataGrid will display a location name.
The URL not only has to open the detail page, it must uniquely identify the record to display on that page.
To identify the record to display on the detail page, select the Data Field option and select a field in your DataSet that uniquely identifies each record. In most cases, the field will consist of a record ID number. In the following example, the field consists of unique location codes.
Dreamweaver creates a URL to the detail page that includes a URL parameter identifying the record the detail page should display. Make a note of the name of the URL parameter because youll use it in the detail page later.
For example, if you select locationDetail.aspx as your detail page, Dreamweaver creates the following URL:
In this case, Dreamweaver creates a URL parameter called CODE
. Dreamweaver copies the name of the data field, but you dont have to use that name. You can change it to something more descriptive, such as recordID, as in the following example.
The {0}
element is a placeholder corresponding to the data fields value. When the page runs, the values of the DataSets CODE field are inserted in the corresponding rows in the DataGrid. For example, if the Canberra, Australia, rental location has the code CBR, then the following URL will be used in the Canberra row in the DataGrid:
locationDetail.aspx?recordID=CBR
Dreamweaver updates the DataGrid on your page.
The next step in creating master/detail pages is to modify the detail page so that it can find the requested record in the database and display it on the page. See Finding and displaying the requested record on the detail page (ASP.NET).