ASP.NET Repeater Example

This control requires no scripting code (no VB, no C#).

<%@ Page Language="VB" %>
<html>
<head>
	<title>ASP.NET Repeater Control Example</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
	
		<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
			<HeaderTemplate>
				<table>
				<tr>
				 <th>ID</th>
				 <th>Last Name</th>
				 <th>First Name</th>
				</tr>
			</HeaderTemplate>

			<ItemTemplate>
			<tr>
				<td bgcolor="#CCFFCC">
				<asp:Label runat="server" ID="Label1" text='<%# Eval("emp_id") %>' />
				</td>
				<td bgcolor="#CCFFCC">
					<asp:Label runat="server" ID="Label2" text='<%# Eval("lname") %>' />
				</td>
				<td bgcolor="#CCFFCC">
					<asp:Label runat="server" ID="Label3" text='<%# Eval("fname") %>' />
				</td>
			</tr>
			</ItemTemplate>

			<!-- THIS IS FOR ALTERNATING ROW COLORS -->
			<AlternatingItemTemplate>
			<tr>
				<td bgcolor="#CCCCFF">
				<asp:Label runat="server" ID="Label4" text='<%# Eval("emp_id") %>' />
				</td>
				<td bgcolor="#CCCCFF">
				 <asp:Label runat="server" ID="Label5" text='<%# Eval("lname") %>' />
				</td>
				<td bgcolor="#CCCCFF">
				 <asp:Label runat="server" ID="Label6" text='<%# Eval("fname") %>' />
				</td>
			</tr>
			</AlternatingItemTemplate>

			<FooterTemplate>
				</table>
			</FooterTemplate>
		</asp:Repeater>

		<asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:PubsConnectionString %>"
			ID="SqlDataSource1" runat="server" SelectCommand="SELECT emp_id, lname, fname FROM employee">
		</asp:SqlDataSource>
	</div>
	</form>
</body>
</html>

The web.config file should have the following database connection string with localhost being the name of the SQL Server:


<connectionStrings>
	<add name="PubsConnectionString" 
		connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=pubs;" />
	</connectionStrings>