源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-11-18 22:49 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:ASP.NET repeater添加序号列的方法
在项目开发过程中,会经常遇到ASP.NET repeater控件添加序号列,有些新手可能还不会,网上搜集整理了一些,需要的朋友可以参考下 ASP.NET repeater添加序号列的方法 [b]1、<itemtemplate>[/b] <tr><td> <%# Container.ItemIndex + 1%> </td></tr> </itemtemplate> [b]2、<itemtemplate>[/b] <tr><td> <%# this.rpResult.Items.Count + 1%> </td></tr> </itemtemplate> [b]3、在<form></form>中添加<Label ID="dd" ></Label>[/b] <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> [b]4、后台实现方法[/b]: 在.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); } } [b]根据条件添加html[/b] <%#Container.ItemIndex == 8 ? "<br><a href = 'http://www.ginchan.com.tw/' target='_blank'><img style='width:338px;heigh:70px' src='/ImportAD/ADmid.gif'> </a>" : ""%>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部