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>
- The class
Container
encapsulates zero or more components.
- The
Container.DataItem
refers to the data source used by the 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( );
}
- The property
DataSource
gets or sets the source containing a list of values used to populate the items within the control.
- The method
DataBind
binds a data source to the invoked server control and all its child controls.
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.