VB.NET•Customize Your View

Listing 4. In the complete ASP.NET page for the Authors example, you create a customized rows and columns view with inline editing using the DataGrid control.

<asp:DataGrid id="pubsDataGrid"
   runat="server" PageSize=5
   AllowPaging="True" AllowSorting="true"
   AutoGenerateColumns="false">
   <Columns>
         <asp:BoundColumn DataField="au_lname"
            SortExpression="au_lname"
            HeaderText="Last Name">
         </asp:BoundColumn>
         <asp:BoundColumn DataField="au_fname"
            SortExpression="au_fname"
            HeaderText="First Name">
         </asp:BoundColumn>
         <asp:TemplateColumn
            HeaderText="Address">
               <ItemTemplate>
                  <asp:Label 
                     text=
                     '<%# Container.DataItem("address")%>'
                  runat="server">
               </asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID=txtAddress
               text='<%# Container.DataItem("address")%>' 
               size="40" runat="server">
            </asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateColumn>
         <asp:BoundColumn DataField="city"
            SortExpression="city"
            HeaderText="City">
         </asp:BoundColumn>
         <asp:BoundColumn DataField="state"
            SortExpression="state"
            HeaderText="State">
         </asp:BoundColumn>
         <asp:BoundColumn DataField="zip"
            SortExpression="zip"
            HeaderText="Zip">
         </asp:BoundColumn>
         <asp:EditCommandColumn EditText="Edit"
            CancelText="Cancel"
            UpdateText="Update">
         </asp:EditCommandColumn>
         <asp:ButtonColumn 
            Text="<img border=0 src=images\del.gif 
            height=16 width=16 alt=Delete>"
            CommandName="Delete">
               <ItemStyle Width="1%"></ItemStyle>
         </asp:ButtonColumn>
   </Columns>
   <ItemStyle 
      Font-Size="X-Small">
   </ItemStyle>
   <AlternatingItemStyle
      BackColor="PaleGoldenrod">
   </AlternatingItemStyle>
   <HeaderStyle Font-Size="X-Small" 
      Font-Bold="True" BackColor="Tan">
   </HeaderStyle>
   <FooterStyle Font-Size="X-Small" 
      Font-Bold="True" BackColor="Tan">
   </FooterStyle>
   <PagerStyle Font-Size="X-Small" 
      Font-Bold="True" NextPageText="Next"
      PrevPageText="Prev" BackColor="Tan">
   </PagerStyle>
</asp:DataGrid>