Professional Documents
Culture Documents
3. Display the page in Design view, and notice that only the LastName and FirstName columns are
displayed in the GridView control. Thats because the Visible property of the Email column has been
set to False. This column must be included in the data source, though, because its the primary key of
the Customers table, and it will be used to display the selected customer in a DetailsView control.
4. Run the application to see that you can page through the customers, but you cant select a customer.
6. Run the application again and click the Select button for any customer. Notice how the formatting for
the selected row changes. Thats because a SelectedRowStyle element is included for the control.
8. Create a data source for the DetailsView control that retrieves each of the columns from the
Customers table for the customer thats selected in the GridView control. Be sure to generate Insert,
Update, and Delete statements and use optimistic concurrency.
9. Use the Add Field dialog box to add a command field that lets the user Edit, Delete, and Add rows.
10. Run the application, display the last page of customers in the GridView control, and select customer
Barbara White. The data for that customer should be displayed in the DetailsView control.
11. Click the Edit button to see that the text boxes that let you edit the data for a customer are all the same
size, and the text box for the address is too small to display the full address for this customer.
12. Click the Cancel button to exit from Edit mode, and close the browser window.
14. Modify the EditItem template for each field except the Email and State fields so the width of the text
box is appropriate for the data, and so the user cant enter more characters than are allowed by the
database LastName, FirstName, and PhoneNumber: 20 characters; Address 40 characters; City 30
characters; and ZipCode 9 characters. Note that you have to define the values for the MaxLength
property (not the width property). The default unit of the MaxLength is the character.
15. Assign a meaningful name to each text box you just modified. Then, add a required field validator to
each of these fields that displays an asterisk to the right of the text box and displays an error message
in the validation summary control if a value isnt entered in the field.
16. Add another data source to the page below the data source for the DetailsView control. This data
source should retrieve the StateCode and StateName columns from the States table and sort the
results by the StateName column.
17. Replace the text box in the EditItem template for the State field with a drop-down list, and bind the
list to the data source you just created so the state name is displayed in the drop-down list and the
state code is stored in the list. Then, use the DataBindings dialog box (hint: the smart tag of the drop
down list > Edit DataBindings and enter Bind(State) in Custom binding) to bind the SelectedValue
property of the drop-down list to the State field of the Customers table.
18. Run the application and click the Edit button in the DetailsView control to make sure you have the
controls in the EditItem template formatted properly.
19. Copy the text boxes, validation controls, and drop-down list you created for the EditItem templates to
the InsertItem templates of the same fields. In addition, add a required field validator to the InsertItem
template for the Email field, and modify the text box so its wider and accommodates a maximum of
25 characters. Note that the same controls (i.e., with the same IDs) can be used in different templates
because one template is rendered at a time. In general IDs should be unique in an aspx file which is
rendered as an html document.
20. Run the application again and click the New button. The InsertItem template should look just like the
EditItem template except that the email field is editable.
22. Run the application and test it to make sure it works correctly.
25. Change the text City: to City, State, Zip:. Then, drag the State label so it follows the City label,
and drag the ZipCode label so it follows the State label.
26. Exit from Template Editing mode, and display the page in Source view. Locate the Item template that
you just modified, enter a comma and a space ( ) between the City and State labels, and enter a
space between the State and ZipCode labels.
<p class="label">City, State, Zip:</p>
<p class="display">
<asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>' />,
<asp:Label ID="StateLabel" runat="server" Text='<%# Bind("State") %>' />
<asp:Label ID="ZipCodeLabel" runat="server" Text='<%# Bind("ZipCode") %>' />
</p>
10
27. Delete the paragraphs from the Item template with the text State: and Zip Code:, along with the
paragraph that follows each of these paragraphs that previously contained the State and ZipCode
labels.
28. Run the application to see that the city, state, and zip code are now displayed on a single line when
the Item template is displayed.
11