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>" : ""%>

时间: 2024-10-11 21:38:27

ASP.NET repeater添加序号列的方法的相关文章

ASP.NET 为GridView添加序号列,且支持分页连续累计显示

为GridView添加序号列,且支持分页连续累计显示,废话不多说,直接上代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 T

GridView添加序号列

在GridView控件第0列添加序号列: <asp:BoundField HeaderText="序号" > <ItemStyle HorizontalAlign="Center" /> <HeaderStyle HorizontalAlign="Center" Width="30px" /> </asp:BoundField> 为GridView添加OnRowDataBound

给DataTable添加序号列

如何在datatable中添加一序号列,编号从1依次递增,并且在第一列? /// <summary>        /// 在DataTable中添加一序号列,编号从1依次递增        /// </summary>        /// <param >DataTable</param>        /// <returns></returns>        private DataTable AddSeriNumToDat

AspxGridView添加序号列

using System.Globalization;//CultureInfo需要 protected void AspxGridView_stock_HtmlDataCellPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableDataCellEventArgs e) { if (e.DataColumn.Caption.Trim() == "序号") { e.Cell.Text = ((e.Vis

dataTable添加序号列

使用render( data, type, row, meta )的参数meta 直接新加一个列 columns: [ {data: "id", title: "id", visible: false, searchable: false}, {data: null, tile: "序号", visible: true, searchable: false}, {data: "name", title: "名称&qu

RadGridView添加序号列

public class RowNumberColumn : GridViewDataColumn { public override System.Windows.FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) { TextBlock textBlock = cell.Content as TextBlock; if (textBlo

oracle 自动添加序号列 排序

select      HSL.sortno,                    HSL.B,                    HSL.A,                    row_number() over(order by sortno desc) xh               from (select  t.B, t.A ,                            case                              when t.B = '

给mysql查询添加序号列

select *,(@number := @number+1) AS number from (select u.mobile,u.`name`, ROUND((select sum(r.realAmount) from t_recharge r where r.userid=u.id and r.status='1' ),2)rechargeSum, ROUND((select sum(w.realAmount) from t_withdrawal w where w.userid=u.id

mysql中给查询结果添加序号列

生成一个字段(非表中字段)用以记录排序   [类比为oracle数据库中的rownum] MySQL中一个表(表名:stuscore) 字段有:id(主键).stuid(学号).sname(学生姓名).subject(课程名称).score(分数) 列出数学成绩排名 (要求显示字段:排名,姓名 , 课程名称, 分数 , 学号) 用于排名的字段,查询时此处将其用 pm表示  select (@i:[email protected]+1)pm,s.* from stuscore s,(select