repeater里添加序号的两种方法(前台,后台)

类别:Asp 点击:0 评论:0 推荐:

前台实现方法:

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

<body onload="show()">

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

后台实现方法:

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

在.cs里添加

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

  }

private 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);
   }
  }

本文地址:http://com.8s8s.com/it/it6958.htm