<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<title>Binding a DataReader to a Repeater Control</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="~/shared/fetchData_oledb.cs" />
<script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e ) {
if ( !IsPostBack ) {
// define the query
string query = "SELECT * FROM Products";
// fetch results of the query into a datareader
myRepeater.DataSource = fetchReader ( query, "dbtutor" );
// bind the repeater to the reader
myRepeater.DataBind ( );
}
}
</script>
<body>
<div class="header"><h2>Binding a <b>DataReader</b> to a <b>Repeater</b> Control</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:repeater id="myRepeater" runat="server">
<headertemplate>
<table width="92%" cellspacing=1 cellpadding=5 style="font:10pt verdana">
<tr style="background:brown; color:snow; height:25pt">
<th>ProductType</th>
<th>ProductCode</th>
<th>ProductName</th>
<th>ProductDescription</th>
<th>UnitPrice</th></tr>
</headertemplate>
<itemtemplate>
<tr>
<td><%# Eval ( "ProductType" ) %></td>
<td><a href='details_prod.aspx?id=<%# Eval ( "ProductCode" ) %>'>
<%# Eval ( "ProductCode" ) %></a></td>
<td><%# Eval ( "ProductName" ) %></td>
<td><%# Eval ( "ProductDescription" ) %></td>
<td align="right"><%# Eval ( "UnitPrice", "{0:c}" ) %></td></tr>
</itemtemplate>
<alternatingitemtemplate>
<tr style="background-color:beige">
<td><%# Eval ( "ProductType" ) %></td>
<td><a href='details_prod.aspx?id=<%# Eval ( "ProductCode" ) %>'>
<%# Eval ( "ProductCode" ) %></a></td>
<td><%# Eval ( "ProductName" ) %></td>
<td><%# Eval ( "ProductDescription" ) %></td>
<td align="right"><%# Eval ( "UnitPrice", "{0:c}" ) %></td></tr>
</alternatingitemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>