ASP.NET webForm表中循环获取行号
Repeate行号属性
Repeate控件显示行号<%#Container.ItemIndex+1 %>
//Container.ItemIndex是从0开始的
有分页的<%#GetXH(Container.ItemIndex) %>
public string GetXH(object index)
{
//返回当前索引+当前行号 StartRecordIndex从1开始/Container.ItemIndex是从0开始的 即(1+0)+1 = 2 即从2开始显示行号
return (anp.StartRecordIndex + int.Parse(index.ToString()) + 1).ToString(); //2,3,4,5,6,7 升序
//返回(总页数-(当前索引 + 当前行号 -1)) 即 (10- 1+(0-1)),(10-2+(7-1))/ 行号是从0开始,所以下标为7是指第8条数据,即每页分8条
//return (anp1.RecordCount - (anp1.StartRecordIndex + int.Parse(index.ToString())-1)).ToString();//7,6,5,4,3,2,1 降序
}
Repeater控制中的ItemTemplate循环5行加一个分隔符
<%#(Container.ItemIndex+1)%5==0?"<hr />":String.Empty %> //当前页+1 取模=0
ASP.NET MVC中 foreach 中获取行号
int index = ViewBag.topnews.IndexOf(item) + 1; //获取行号
//mvc前端foreach最后一条
if (item != ViewBag.topnews[ViewBag.topnews.Count - 1])
{
}