码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET repeater添加序号列的方法

时间:2015-01-02 15:56:22      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

ASP.NET repeater添加序号列的方法 

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

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

3、在<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); 


根据条件添加html 
<%#Container.ItemIndex == 8 ? "<br><a href = ‘http://www.ginchan.com.tw/‘ target=‘_blank‘><img style=‘width:338px;heigh:70px‘ src=‘/ImportAD/ADmid.gif‘> </a>" : ""%>

ASP.NET repeater添加序号列的方法

标签:

原文地址:http://www.cnblogs.com/zq20/p/4198471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!