Binding Data to Data Web Controls

4GuysFromRolla – Binding a Scalar Array to Data Web Control

The ASP.NET data Web controls can display any data that implements either the IEnumerable interface or the IListSource interface. They are bound through two lines of codes:

  • The object is assigned to the data Web control’s DataSource property
  • The data Web control’s DataBind() method is called

The syntax for displaying a particular field in a data Web control depends upon the data Web control being used.

Two examples:

  • DataGrid
    <asp:DataGrid id="dgArrayAutoGenerate" runat="server"
  • DataList
    <asp:DataList id="dlFibs" runat="server" RepeatColumns="3"
         GridLines="Both" CellPadding="10"
        <b><%# Container.DataItem %></b>

By Bryan Xu