ASP.NET Test-Drive: Listing 1.
Binding GridView to a Customer object using ItemType.
<asp:GridView ID="GridView1"
ItemType="Sample45.Customer"
runat="server" AutoGenerateColumns="False"
DataKeyNames="CustomerID">
<Columns>
<asp:TemplateField HeaderText="CompanyName"
SortExpression="CompanyName">
<EditItemTemplate>
<%#: Item.CustomerID%>
</EditItemTemplate>
<ItemTemplate>
<%#: Item.CustomerID%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CompanyName"
SortExpression="CompanyName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text="<%#: BindItem.CompanyName%>">
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<%#: Item.CompanyName%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
About the Author
Peter Vogel is a system architect and principal in PH&V Information Services. PH&V provides full-stack consulting from UX design through object modeling to database design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His blog posts on user experience design can be found at http://blog.learningtree.com/tag/ui/.