将某列表添加序号,小编也遇到了好多次了,由于前端有各种各样的框架,有时候想要单纯的靠前端实现还是需要考虑各种各样的问题,最终小编还是觉得使用后端的方式更加妥当
int UserId = ctx.GetInt("Uid");//前端获取的参数,ctx为本项目封装的部分无需理会
int pagesize = ctx.GetInt("jtPageSize");//每页页数
int startindex = ctx.GetInt("jtStartIndex") / pagesize + 1;//开始的页码(或点击的页码)
int total = 0;
IIntellManuSchool_PointsBL bl = new IntellManuSchool_PointsBL();
List<IntellManuSchool_PointsDetailV> lst = bl.GetPointsDetailByPage(UserId, pagesize, startindex, out total);//获取列表的方法,不是小编主要想要讲的东西
// ***************************************************主要代码start**********************************
List<IntellManuSchool_PointsDetailV> mblist = new List<IntellManuSchool_PointsDetailV>();//该list中的实体要和获取的列表的实体相同
int i = startindex - 1;
i = i * pagesize;
foreach (var j in lst)
{
i++;
j.RowNum = i;
mblist.Add(j);
}
lst = mblist;
var lists = from d in lst
orderby d.RowNum
select new
{
d.RowNum,//RowNum需要手动在实体中添加
d.Id,
d.EnterpriseName
};//该lists即为最终带有序号的list,即使翻页也不会错乱
// ***************************************************主要代码end**********************************
//实体类 该实体类由于和公司框架保持一致所以这样写,正常实体类添加RowNum一样可以达到目的
[Serializable]
public partial class IntellManuSchool_PointsDetailV : IntellManuSchool_UserPoints, IEntity<System.Int32>
{
#region Force Static Check
public const string _Id = "Id";
public const string _EnterpriseName = "EnterpriseName";
public const string _RowNum = "RowNum";//手动添加
#endregion
#region Property
#region Id
private System.String m_Id = "";
public System.String Id
{
get
{
return this.m_Id;
}
set
{
this.m_Id = value;
}
}
#endregion
#region EnterpriseName
private System.String m_EnterpriseName = "";
public System.String EnterpriseName
{
get
{
return this.m_EnterpriseName;
}
set
{
this.m_EnterpriseName = value;
}
}
#endregion
#region RowNum
private System.Int32 m_RowNum = 0;
public System.Int32 RowNum
{
get
{
return this.m_RowNum;
}
set
{
this.m_RowNum = value;
}
}
#endregion
#endregion
}