设为首页 加入收藏

TOP

WebForm Repeater使用(一)
2019-09-03 02:14:10 】 浏览:24
Tags:WebForm Repeater 使用

Repeater:

HeaderTemplate在加载开始执行一遍

ItemTemplate : 有多少条数据,执行多少遍

FooterTemplate在加载最后执行一遍

AlternatingItemTemplate交替项模板

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table style="background-color:navy;text-align:center">
                    <tr style="color:white;padding:10px;">
                        <td>UserName</td>
                        <td>PsssWord</td>
                        <td>NickName</td>
                        <td>Sex</td>
                        <td>Birthday</td>
                        <td>Nation</td>
                    </tr>
             </HeaderTemplate>
            <ItemTemplate>
                <tr style="background-color:yellow">
                    <td><%#eva l("UserName")%></td>
                    <td><%#eva l("PassWord")%></td>
                     <td><%#eva l("NickName")%></td>
                    <td><%#eva l("Sex")%></td>
                     <td><%#eva l("birthday")%></td>
                    <td><%#eva l("Nation")%></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
              </table>
            </FooterTemplate>            
        </asp:Repeater>
        



    </form>
</body>
</html>

数据绑定

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Repeater1.DataSource = new UsersDA().Select();
            Repeater1.Users:


/// <summary>
    /// 性别
    /// </summary>
    public bool Sex
    {
        get { return _Sex; }
        set { _Sex = value; }
    }

    public string SexStr
    {
        get { return _Sex ? "" : ""; }
    }


    private DateTime _Birthday;

    /// <summary>
    /// 生日
    /// </summary>
    public DateTime Birthday
    {
        get { return _Birthday; }
        set { _Birthday = value; }
    }

    public string BirthdayStr
    {
        get { return _Birthday.ToString("yyyy年MM月dd日"); }
    }


    private string _Nation;

    /// <summary>
    /// 民族
    /// </summary>
    public string Nation
    {
        get { return _Nation; }
        set { _Nation = value; }
    }

    public string NationName
    {
        get { return new NationData().Select(this._Nation).NationName; }

    }

    public string Age
    {
        get { return (DateTime.Now.Year - this._Birthday.Year).ToString(); }
    }

    public string Red
    {
        get
        {
            string end = "";
            if (Convert.ToInt32(Age) >= 16)
            {
                end = "background-color:red;";
            }
            return end;
        }
    }

数据操作类

public class UsersDA
{
    SqlConnection conn = null;
    SqlCommand cmd = null;
    public UserDA()
    {
        conn = new SqlConnection("server=.;database=Data0617;user=sa;pwd=123");
        cmd = conn.CreateCommand();
    }
    public List<Users> select()
    {
        List<Users> list = new List<Users>();
        cmd.CommandText = "select * from Users";
        conn.Open();

        SqlDataReader dr = cmd.ExecuteReader();

        if (dr.HasRows)
        {
            while (dr.Read())
            {
                Users data = new Users();
                data.UserName =
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇sql子查询的例子 下一篇C# 时间戳与DateTime间的互相转换

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目