|
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
<%@ 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")%>
<%# Container.DataItem("Zip")%><br>
Tel=<%# Container.DataItem("Telephone")%><BR>
Fax=<%# Container.DataItem("Fax")%><br>
</small>
</itemtemplate>
</ASP:Datalist>
</body></html>
|