在项目开发过程中,会经常遇到asp.net repeater控件添加序号列,有些新手可能还不会,网上搜集整理了一些,需要的朋友可以参考下

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取得CheckBox选中的某行某个值的c#写法
  • asp.net repeater手写分页实例代码
  • asp.net Repeater之非常好的数据分页
  • asp.net中让Repeater和GridView支持DataPager分页
  • asp.net Repeater 数据绑定的具体实现(图文详解)
  • asp.net 遍历repeater中的控件的几种方式
  • asp.net下Repeater使用 AspNetPager分页控件
  • asp.net repeater实现批量删除
  • asp.net Repeater控件的说明及详细介绍及使用方法
  • asp.net Repeater 数据绑定代码
  • JQuery实现Repeater无刷新批量删除(附后台asp.net源码)
  • 决定何时使用 DataGrid、DataList 或 Repeater(ASP.NET 技术文章)
  • ASP.NET笔记之 Repeater的使用
  • asp.net DataList与Repeater用法区别
  • 详解ASP.NET数据绑定操作中Repeater控件的用法
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。