E:\web\learnaspcom\htdocs\freebook\learn\ubtoc.xml LearnAsp.com - ASP ASP.net Free Lessons
Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
xxx

Data Template: DataList for multi-columns by Charles Carroll

This page demonstrates how to use datalist templates to display database info in multiple columns with any arbitrary look and feel without having to resort to LOOPs, MoveNext, etc. One primary difference between the datalist control and the repeater controls is multi-column capabilities.

http://www.aspng.com/quickstart/aspplus/doc/webdatalist.aspx
has more info on datalists.

Whenever one needs a specific field value in a template:
<%# DataBinder.Eval(Container.DataItem, "fieldname")%>
is the expression that will obtain it.

The general format of a template is:

<ASP:Datalist id="whatever" runat="server">

<headertemplate>
    xxxx
</headertemplate>

<itemtemplate>
    xxxx
</itemtemplate>

<AlternatingItemTemplate>
   xxxx
</alternatingitemtemplate>

<footertemplate>
   xxx
</footertemplate>
</ASP:Datalisr>

Here is a sample datalist template showing the data from New York layed out in multiple columns.

   filename=\experiments\templates\nydatalist.aspx

<Test Script Below>


<%@ Import Namespace="System.Data.OLEDB" %>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
    Dim strConn as string ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("/experiments/data/biblio.mdb") & ";" 
    Dim strSQL as string ="select * from publishers where state='NY'"
    Dim Conn as New OLEDBConnection(strConn)
    Dim Cmd as New OLEDBCommand(strSQL,Conn)
    Conn.Open()
    thedata.DataSource = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
    thedata.DataBind()
End Sub
</script>
<html><head>
<title>New York Data In Templates</title>
</head>
<body bgcolor="#FFFFFF">
<ASP:Datalist id="thedata" repeatcolumns="3" repeatdirection="vertical" repeatlayout="table" runat="server">

    <itemtemplate>
       <hr>
       <small>
       PubID=<b><%# Container.DataItem("PubID")%></b><BR>
       <%# Container.DataItem("Company Name")%><br>
       <%# Container.DataItem("City")%>,
       <%# Container.DataItem("State")%>
       &nbsp;&nbsp;<%# Container.DataItem("Zip")%><br>
       Tel=<%# Container.DataItem("Telephone")%><BR>
       Fax=<%# Container.DataItem("Fax")%><br>
       </small>
    </itemtemplate>

</ASP:Datalist>
</body></html>
Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site