| Data Binding in ASP.Net 2.0 |
| |
| DataList Web Server Control |
| |
| The DataList supports a richer feature set than the Repeater, including automatic generation of <table>, <tr> and <td> tags (optional) to hold each list item. DataList also requires that you create templates to define the content and layout of each item.
DataList supports seven different templates. Beside those found in the Repeater, the DataList also provides the SelectedItemTemplate and the EditItemTemplate - to allow selecting and editing of items. |
| |
| The layout of the DataList control is controlled with the RepeatLayout property. Setting this property to RepeatLayout. Table will display the DataList in a table format, while RepeatLayout.Flow displays the DataList without a table structure.
Similar to the Repeater, the DataList, at the very minimum, needs the ItemTemplate to be defined to display "its" items. |
| |
| As the initial design time rendering of the DataList suggest, you need to specify at least the ItemTemplate for the list. |
| |
| Right click the DataList and select "Header and Footer Templates" from the drop down list, to edit the templates. Select "End Template Editing" from the right-click menu. |
| |
| Note that the design time rendering of the control has not changed, however when you switch to the "aspx/html" view the asp markup will be: |
| |
<asp:DataList id="DataList1" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<FooterTemplate>
<asp:HyperLink
id="HyperLink1"
runat="server"
navigateurl="anyurlstring">
delphi.about.com
</asp:HyperLink>
</FooterTemplate>
</asp:DataList> |
| |
| It is important to note that if you run the project now, you'll get an "empty" page at run time (rendered to the user in a Web Browser). DataList will not render if the DataBind method is not called. |
| |
| To show data in the DataList control you have to configure it with any of Data Source Controls. For the sake of simplicity you can also use an ArrayList variable to hold the list of items that will be displayed by the DataList. |
| |
|
| |