C# repeater控件里添加序号的4种方法
分类:.Net知识问答| 发布:camnprbubuol| 查看:1015 | 发表时间:2010/12/28
4 | <%# Container.ItemIndex + 1%> |
4 | <%# this .rpResult.Items.Count + 1%> |
两种其它方法:
在<form></form>中添加<Label ID="dd" ></Label>
<body nload="show()">
01 | <Script. Language= "JScript" > |
06 | var bj = document.all.tags( "LABEL" ); |
08 | for (i=0;i<obj.length;i++) |
12 | document.all[ "dd" ][i].innerHTML=i+1; |
4、后台实现方法
后台实现方法:
在.aspx里添加<asp:Label id="Label1" Runat="server"></asp:Label>
在.cs里添加
1 | ** void InitializeComponent() |
2 | { this .Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler( this .Repeater1_ItemDataBound); |
4 | this .Load += new System.EventHandler( this .Page_Load); |
}
01 | ** void Repeater1_ItemDataBound( object source, System.Web.UI.WebControls.RepeaterItemEventArgs e) |
04 | if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) |
08 | ((Label)e.Item.FindControl( "Label1" )).Text = Convert.ToString(e.Item.ItemIndex + 1); |