User Interface: Default.aspx (Cont.)


The ASP.NET data binding enables page developers to hierarchically bind control properties to data container values. Code located within a <%# %> code block is only executed when the DataBind method of its parent control container is invoked. ASP.NET automatically generates the following source code Default.aspx after the interface is created by developers.

(Simplified) Default.aspx
<%@ Page Language="C#" AutoEventWireup="false"
  CodeDatabase="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
 <body>
  <form id="form1" runat="server">
   An ASP.NET Database Processing Example
   Name: <asp:TextBox ID="authorName" runat="server" Width="150px" />
   Email: <asp:TextBox ID="email" runat="server" Width="150px" />
   <asp:Button ID="insert" runat="server" Text="Insert" />
   <asp:Button ID="delete" runat="server" Text="Delete" />
   <asp:Button ID="search" runat="server" Text="Search" />

   The search results are
   <asp:Repeater ID="searchResult" runat="server">
    <HeaderTemplate>
     <table border="1">
      <tr bgcolor="#b0c4de">
       <th>ID</th><th>Name</th><th>Email</th>
      </tr>
    </HeaderTemplate>

    <ItemTemplate>
     <tr bgcolor="#f0f0f0">
      <td><%#DataBinder.Eval(Container.DataItem,"authorID")%></td>
      <td><%#DataBinder.Eval(Container.DataItem,"authorName")%></td>
      <td><%#DataBinder.Eval(Container.DataItem,"email")%></td>
     </tr>
    </ItemTemplate>

    <FooterTemplate></table></FooterTemplate> 
   </asp:Repeater>
  </form>
 </body>
</html>