咨询电话:186 7916 6165 咨询电话:186 7916 6165 (微信同号)    在线QQ:181796286
NEWS BLOG ·
学无止境
关注开优网络 关注前沿
ASP.NET 获得指定字符串中开始和结束中间的值
移动端HTML5页面通过地址调起高德地图、百度地图定位导航

ASP.NET 循环中获取行号

发表日期:2020-05-21    文章编辑:    浏览次数:3088    标签:

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])
{

}