数据绑定显示web页面

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Repeater.aspx.cs" Inherits="Repeater" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style>
        table {
            width: 500px;
            border: 1px solid #ccc;
            border-collapse: collapse;
        }

            table td {
                border: 1px solid #ccc;               
                padding: 3px;
            }
    </style>
</head>
<body>
    <form id="form1" runat="server">       
        <div>
            <asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <td>编号</td>
                            <td>姓名</td>
                            <td>票数</td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%# Eval("peopleId") %></td>
                        <td><%# Eval("peopleName")%></td>
                        <td><%# Eval("Num") %></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>            
        </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Repeater : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sql = "select * from people";
            DataTable dt = SQLHelper.ExecuteDataTable(sql);
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }
    }
}

绑定 :SqLDataSource控件 <%#DataBinder.Eval(container.DataItem,"字段")%>

 

posted @ 2018-03-16 08:08  你的斗志并没有失去  阅读(196)  评论(0编辑  收藏  举报