WebForm Repeater使用

來源:互聯網
上載者:User

標籤:

Repeater:

HeaderTemplate - 在載入開始執行一遍

ItemTemplate - 有多少條資料,執行多少遍

FooterTemplate - 在載入最後執行一遍

AlternatingItemTemplate - 交替項目範本

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="lianxi.aspx.cs" Inherits="lianxi" %><!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></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><%#Eval("UserName")%></td>                    <td><%#Eval("PassWord")%></td>                     <td><%#Eval("NickName")%></td>                    <td><%#Eval("Sex")%></td>                     <td><%#Eval("birthday")%></td>                    <td><%#Eval("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.DataBind();        }    }

庫存預警:
通過某個屬性值判斷後,將某條資料的樣式變更

屬性擴充的方式,寫一個返回string類型的屬性,返回的是CSS樣式表樣式

/// <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;        }    }
<ItemTemplate>                <tr class="tr_Item" style="<%#Eval("Red")%>">                    <td><%#Eval("UserName") %></td>                    <td><%#Eval("PassWord") %></td>                    <td><%#Eval("NickName") %></td>                    <td><%#Eval("SexStr") %></td>                    <td><%#Eval("BirthdayStr") %></td>                    <td><%#Eval("Age") %></td>                    <td><%#Eval("NationName") %></td>                </tr>            </ItemTemplate>

光棒效果

滑鼠移入改變顏色

<style type="text/css">        #tb1 {            width: 100%;            background-color: navy;            text-align: center;        }        #tr_head {            color: white;        }        .tr_Item {            background-color: white;        }        .tr_Item2 {            background-color: #e0e0e0;        }    </style>    <script type="text/javascript">        window.onload = function () {            var items = document.getElementsByClassName("tr_Item");            var oldColor = "";            for (var i = 0; i < items.length; i++) {                items[i].onmouseover = function () {                    oldColor = this.style.backgroundColor;                    this.style.backgroundColor = "yellow";                };                items[i].onmouseout = function () {                    this.style.backgroundColor = oldColor;                };            }        };    </script>

 

WebForm Repeater使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.