Slide 13.1: Data binding syntax: <%#  %>
Slide 13.3: Database connection
Home

Data Binding Syntax: <%#  %> (Cont.)


Within the DataList, the template for one item is specified. The content of the item template is specified using a data binding expression:
   <asp:datalist id="MyList" runat="server">
     <ItemTemplate>
       Here is a value: <%# Container.DataItem %>
     </ItemTemplate>
   </asp:datalist>
In this case the data source of the MyList control is set programmatically, and then DataBind( ) is called.
   protected void Page_Load( object sender, EventArgs e ) {
     ArrayList Items = new ArrayList( );
     Items.Add( "One" );
     Items.Add( "Two" );
     Items.Add( "Three" );
     MyList.DataSource = Items;
     MyList.DataBind( );
   }
Calling the DataBind method of a control causes a recursive tree walk from that control on down in the tree; the DataBinding event is raised on each server control in that hierarchy, and data binding expressions on the control are evaluated accordingly.