Repeater Control 2
Create an ASP.NET website. Under the website create a new folder named "Repeater 02". Under the folder create a web form named "Default".
Database is Northwind
Add a ConnectionString in Web.Config named "NorthwindConnectionString"
Result:
Default.aspx
=========
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Repeater02_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Repeater Test 02</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table style="border:1px solid #999999">
<tr style="background-color:Green">
<td style="width:150px"><center>CustomerID</center></td>
<td style="width:150px"><center>OrderDate 1</center></td>
<td style="width:250px"><center>OrderDate 2</center></td>
<td style="width:100px"><center>Freight</center></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width:150px"><center><%#DataBinder.Eval(Container.DataItem,"CustomerID" )%></center></td>
<td style="width:150px"><center><%#DataBinder.Eval(Container.DataItem,"OrderDate","{0:d}") %></center></td>
<td style="width:250px"><center><%#DataBinder.Eval(Container.DataItem,"OrderDate","{0:D}") %></center></td>
<td style="width:100px"><center><%#DataBinder.Eval(Container.DataItem, "Freight", "${0:F2}")%></center></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
============================================================================================
Default.aspx.cs
==========
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Repeater02_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
string cmdString = "select top 10 * from orders";
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmdString, con);
DataSet ds = new DataSet();
sda.Fill(ds, "Orders");
Repeater1.DataSource = ds.Tables["Orders"];
Repeater1.DataBind();
con.Close();
}
}
}