File: SkinFile.skin (excerpt)
<asp:DetailsView runat="server" CssClass="GridMain"
CellPadding="4" GridLines="None">
<RowStyle CssClass="GridRow" />
<HeaderStyle CssClass="GridHeader" />
</asp:DetailsView>
Here, we’ve defined a similar style to the GridView control, which will ensure
that our page has a consistent appearance. Save your work, open AddressBook.as-
px in the browser, and select an employee. You should see something similar to
Figure 11.11.
We’re really making progress now. There’s only one problem—our employee re-
cords don’t include any addresses, and at this moment there’s no way to add
any! Let’s take care of this.
GridView and DetailsView Events
In order to use the GridView and DetailsView controls effectively, we need to
know how to handle their events. In this section, we’ll learn about the events
raised by these controls, with an emphasis on the events that relate to editing
and updating data, as our next goal will be to allow users to edit the employee
details in the DetailsView.
Earlier, you learned how to respond to the user’s clicking of the Select button by
handling the GridView’s SelectedIndexChanged event. Soon you’ll implement
editing functionality, which you’ll achieve by adding an Edit button to the
DetailsView control. The editing features of the GridView and the DetailsView
are very similar, so you can apply the same principles, and even almost the same
code, to both of them.
Both the GridView and DetailsView controls support Edit command buttons,
which will place Edit buttons in the control when the page loads. Once one of
the Edit buttons has been clicked, the row (in case of GridView) or the entire
form (in case of DetailsView) will become editable, and instead of an Edit button,
users will see Update and Cancel buttons.
These features are pretty amazing, because you can achieve this “edit mode”
without writing any HTML at all: the columns know how to render their editable
modes by themselves. If you don’t like their default edit mode appearances, you
can customize them using templates.
452
Chapter 11: Managing Content Using Grid View and Details View