ASP.NET webForm表中循環(huán)獲取行號(hào)
Repeate行號(hào)屬性
Repeate控件顯示行號(hào)<%#Container.ItemIndex+1 %>
//Container.ItemIndex是從0開(kāi)始的
有分頁(yè)的<%#GetXH(Container.ItemIndex) %>
public string GetXH(object index)
{
//返回當(dāng)前索引+當(dāng)前行號(hào) StartRecordIndex從1開(kāi)始/Container.ItemIndex是從0開(kāi)始的 即(1+0)+1 = 2 即從2開(kāi)始顯示行號(hào)
return (anp.StartRecordIndex + int.Parse(index.ToString()) + 1).ToString(); //2,3,4,5,6,7 升序
//返回(總頁(yè)數(shù)-(當(dāng)前索引 + 當(dāng)前行號(hào) -1)) 即 (10- 1+(0-1)),(10-2+(7-1))/ 行號(hào)是從0開(kāi)始,所以下標(biāo)為7是指第8條數(shù)據(jù),即每頁(yè)分8條
//return (anp1.RecordCount - (anp1.StartRecordIndex + int.Parse(index.ToString())-1)).ToString();//7,6,5,4,3,2,1 降序
}
Repeater控制中的ItemTemplate循環(huán)5行加一個(gè)分隔符
<%#(Container.ItemIndex+1)%5==0?"<hr />":String.Empty %> //當(dāng)前頁(yè)+1 取模=0
ASP.NET MVC中 foreach 中獲取行號(hào)
int index = ViewBag.topnews.IndexOf(item) + 1; //獲取行號(hào)
//mvc前端foreach最后一條
if (item != ViewBag.topnews[ViewBag.topnews.Count - 1])
{
}