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

來源:互聯網
上載者:User

標籤:

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添加序號列的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.