Repeater Control 1

Create an ASP.NET website. Under the website create a new folder named "Repeater 01". 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="Repeater01_Default" %>
<%@ Import Namespace="System.Data" %>

<!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 1</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
            <p>Repeater Test</p>
        </HeaderTemplate>
        <ItemTemplate>
        <table>
            <tr>
                <td>고객 아이디:</td>
                <td><%#((DataRowView)Container.DataItem)["CustomerID"] %></td>
            </tr>
            <tr>
                <td>주문 시간:</td>
                <td><%#Eval("OrderDate","{00:yyyy-MM-dd}") %></td>
            </tr>
        </table>            
        </ItemTemplate>
        <SeparatorTemplate>
            <hr align="left" size="1px" width="300px" >
        </SeparatorTemplate>
        <FooterTemplate>
            <hr />
        </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 Repeater01_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();
        }
    }
}

posted @ 2009-01-03 18:53  OOK  阅读(155)  评论(0编辑  收藏  举报