zoukankan      html  css  js  c++  java
  • repeater里添加序号的4种方法

    repeater里添加序号的4种方法
    2009年07月24日 星期五 08:43

    两种简洁方法

    1、<itemtemplate>
    <tr><td>
    <%# Container.ItemIndex + 1%>
    </td></tr>
    </itemtemplate>


    2、<itemtemplate>
    <tr><td>
    <%# this.rpResult.Items.Count + 1%>
    </td></tr>
    </itemtemplate>


    两种其它方法:

    在<form></form>中添加<Label ID="dd" ></Label>

    <body nload="show()">

    <Script. Language="JScript">
          function show()
       {
    var bj = document.all.tags("LABEL");
    for (i=0;i<obj.length;i++)
    {
    document.all["dd"][i].innerHTML=i+1;
    }
       }
       </script>

    4、后台实现方法


    后台实现方法:

    在.aspx里添加<asp:Label id="Label1" Runat="server"></asp:Label>

    在.cs里添加

    ** void InitializeComponent()
    {   
       this.Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater1_ItemDataBound);
       this.Load += new System.EventHandler(this.Page_Load);

    }

    ** void Repeater1_ItemDataBound(object source, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
       {
        ((Label)e.Item.FindControl("Label1")).Text = Convert.ToString(e.Item.ItemIndex + 1);
       }
    }


       本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

  • 相关阅读:
    《当程序员的那些狗日日子》(二十六)再下决心
    创建本地数据库
    Servlet的开发和使用
    tomcat7不能创建解决办法
    windows系统纯净版下载
    Linux打包命令
    Filter的开发和使用
    C语言地址传递和值传递简析
    Servlet生命周期
    Java EE架构
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1541351.html
Copyright © 2011-2022 走看看