<%@ Page Language="C#" %>
<html>
<head runat="server">
<title>ASP.NET Repeater Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label1"
text='<%# Eval("CategoryName") %>' />
</td>
<td bgcolor="#CCFFCC">
<asp:Label runat="server" ID="Label2"
text='<%# Eval("Description") %>' />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td >
<asp:Label runat="server" ID="Label3"
text='<%# Eval("CategoryName") %>' />
</td>
<td >
<asp:Label runat="server" ID="Label4"
text='<%# Eval("Description") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource
ConnectionString=
"<%$ ConnectionStrings:NorthwindConnectionString %>"
ID="SqlDataSource1" runat="server"
SelectCommand="SELECT [CategoryID], [CategoryName],
[Description] FROM [Categories]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
The example requires a connection string that can be used to connect to the sample Northwind database in Microsoft SQL Server. The connection string must be defined in the <connectionStrings> element of the application's Web.config file. The <connectionStrings> section might look like the following example:
<configuration>
<connectionStrings>
<add
name="NorthwindConnectionString"
connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;" />
</connectionStrings>
<system.web>
<!-- Other configuration settings -->s
</system.web>
</configuration>
No comments:
Post a Comment