Databases Reference
In-Depth Information
FIGURE 4.1 Customer Information page.
The markup in Listing 4.1 takes advantage of the field templating functionality, making it
clearer and more concise than its equivalent based on regular ASP.NET controls. However,
in this example, only the read-only template is defined. If you were to reuse this page and
allow users to edit information of existing customers or create new customer records as
well, you would also need to define the EditItemTemplate and InsertItemTemplate in the
FormView control, in addition to the read-only ItemTemplate that exists now. Defining
multiple item templates in a single FormView control significantly increases the amount of
code and complexity of the page. However, even if you split this page into separate
Customer Details, Customer Edit, and Customer Insert pages, the problem still stands—the
amount of code will grow even more, except that it will be split among multiple files.
It would be great to have this entity-level presentation logic (that is, how a Customer
Information form is laid out) defined separately so you could reuse the rest of the presen-
tation and data access logic on this page without duplicating it.
LISTING 4.1
Customer Information Page (Markup)
<%@ Page Language=”C#”
MasterPageFile=”~/Site.master” CodeBehind=”SamplePage.aspx.cs”
Inherits=”WebApplication.Samples.Ch04.FormView.SamplePage” %>
<asp:Content runat=”server” ContentPlaceHolderID=”main”>
<asp:ValidationSummary runat=”server” />
<asp:FormView ID=”form” runat=”server” DataSourceID=”dataSource”>
<ItemTemplate>
<label>ID:</label>
<asp:DynamicControl runat=”server” DataField=”CustomerID” />
<label>Name:</label>
<asp:DynamicControl runat=”server” DataField=”ContactName” />
<fieldset><legend>Address</legend>
<label>Street:</label>
<asp:DynamicControl runat=”server” DataField=”Address” /><br />
Search WWH ::




Custom Search