Bind data to asp:Repeater with itemtemplate, alternatingitemtemplate, separatortemplate and footertemplate
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
If Not IsPostBack Then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("EmployeeDatabase.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select ID, FirstName " _
& "From Employee " _
& "Order By FirstName", DBConn)
DBCommand.Fill(DSPageData, _
"Employee")
repDepts.DataSource = _
DSPageData.Tables("Employee").DefaultView
repDepts.DataBind()
End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Creating a Basic Repeater Control</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<asp:repeater
id="repDepts"
runat="server"
>
<headertemplate>
<I>Below is a list of all the employee.</I><BR><BR>
</headertemplate>
<itemtemplate>
<%# "<B>Department:</B> " _
& DataBinder.Eval(Container.DataItem, "ID") _
& " - " _
& DataBinder.Eval(Container.DataItem, "FirstName")
%>
<BR>
</itemtemplate>
<alternatingitemtemplate>
<I><%# "<B>Department:</B> " _
& DataBinder.Eval(Container.DataItem, "ID") _
& " - " _
& DataBinder.Eval(Container.DataItem, "FirstName")
%></I>
<BR>
</alternatingitemtemplate>
<separatortemplate>
<HR>
</separatortemplate>
<footertemplate>
<BR><I>All records have been displayed.</I>
</footertemplate>
</asp:repeater>
</form>
</BODY>
</HTML>
EmployeeDatabase.zip( 10 k)Related examples in the same category