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