One of the easiest ways to add data manipulation to a .NET application is to use the <asp:FormView>
control. This control is a templated control, with templates for <ItemTemplate>
(ReadOnly view), <InsertItemTemplate>
(Insert), <EditItemTemplate>
(Edit), and <EmptyDataTemplate>
.
The following code snippet shows the basic syntax of the control, which is similar to the others that we have implemented:
<asp:FormView ID="contactFormView" DataSourceID="contactDetailSource" DataKeyNames="Id" runat="server"> </asp:FormView>
One property, which is of particular interest to us, that this control exposes is the DataKeyNames
property. By setting this property, we tell the control the name of the Primary Key field or fields (separated by a comma) that make a unique record. To set this property for our objects, we just need to say:
DataKeyNames="Id"
As with all templated controls, we can use CSS to "spruce up" the look of...