Database
  Home arrow Database arrow Page 4 - ADO.NET 101: Data Rendering with a DataLis...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

ADO.NET 101: Data Rendering with a DataList Control Introduction
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 9
    2005-11-29

    Table of Contents:
  • ADO.NET 101: Data Rendering with a DataList Control Introduction
  • Displaying Data from DataReader with a DataList Control
  • Data from a DataReader
  • Designing the ItemTemplate
  • Displayed data from DataReader

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    ADO.NET 101: Data Rendering with a DataList Control Introduction - Designing the ItemTemplate


    (Page 4 of 5 )

    ItemTemplate is an item that must be configured. The actual table cells in this template are shown in the html. This would appear to be similar to what you would have needed  to bring the recordset values into a table cell using the ASP syntax <%...%>, enclosing the databound information. In this case however, you have Framework supported classes making this possible.

    <ItemTemplate>
    <tr>
    <td>
    <%#DataBinder.Eval(Container,"DataItem.fname")%>
    </td>
    <td>
    <%#DataBinder.Eval(Container,"DataItem.lname")%>
    </td>
    <td>
    <%#DataBinder.Eval(Container,"DataItem.emp_id")%>
    </td>
    <td>
    <%#DataBinder.Eval(Container,"DataItem.hire_date")%>
    </td>
    </tr>
    </ItemTemplate> 

    DataBinder is from the System.Web.UI.DataBinder class and Eval () is the method which takes the following arguments: the first argument is the Object container and the second a string expression. Each of these string expressions is coming from the data source's fields.

    At this point the program has enough information to display the data in the DataReader. The UI would appear as follows:

    The HeaderTemplate

    The HeaderTemplate would normally be used for displaying the column headings in a readable text format. In this case fname would be substituted with First Name in the header template. The following picture shows how you may change the style of the various templates, and their individual properties of the DataList. The following HTML elements were added to produce the header information. In the UI the style of the header was slightly modified as shown.

    <HeaderTemplate>
    <table>
    <tr bgcolor="#ffffcc" style="COLOR: #0033cc>
    <td>First Name</td>
    <td>Last Name</td>
    <td>Employee ID</td>
    <td>Hire Date</td>
    </tr>
    </HeaderTemplate>

    The AlternatingItemTemplate

    As mentioned earlier, this is optional and is rendered in display only when defined in the source. The following html shows how this is formatted. It is the same as the ItemTemplate, except that the cell color is different.  The ItemTemplate cells are also formatted so that there is a distinction between ItemTemplate and the AlternatingItemTemplate.

    <tr>
    <td bgcolor="#ffcccc" align="left">
    <%#DataBinder.Eval(Container,"DataItem.fname")%>
    </td>
    <td bgcolor="#ffcccc" align="left">
    <%#DataBinder.Eval(Container,"DataItem.lname")%>
    </td>
    <td bgcolor="#ffcccc" align="left">
    <%#DataBinder.Eval(Container,"DataItem.emp_id")%>
    </td>
    <td bgcolor="#ffcccc" align="left">
    <%#DataBinder.Eval(Container,"DataItem.hire_date")%>
    </td>
    </tr>
    The FooterTemplate

    The footer template was not defined in this tutorial. In this section one may insert some aggregate information, or some date information.

    More Database Articles
    More By Jayaram Krishnaswamy


       · In a series of articles I have tried to cover data rendering from an SQL Server...
     

    DATABASE ARTICLES

    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT