C# 通过LINQ显示DataTable中记录的序列号和数据绑定 public List NotificationManagementData(IEnumerable-completintentry,int-currentUserId) { 返回completintentry.Select((条目,索引)=>newstring[] { (索引+1).ToString(), GetLinks(currentUserId,条目), entry.state\u Id, entry.refType, entry.request, 进入。行动, Common.Encrypt(currentUserId.ToString(),entry.id.ToString()) }).ToList(); }
为了显示每个记录的序列号,我只是在每个条目的索引值上加1。如果所有记录都在一页中,上面的代码工作正常。但如果有超过1页,则序列号在第二页中再次从1开始。请帮助我在接下来的几页中继续获得序列号。提前感谢假设分页是在C# 通过LINQ显示DataTable中记录的序列号和数据绑定 public List NotificationManagementData(IEnumerable-completintentry,int-currentUserId) { 返回completintentry.Select((条目,索引)=>newstring[] { (索引+1).ToString(), GetLinks(currentUserId,条目), entry.state\u Id, entry.refType, entry.request, 进入。行动, Common.Encrypt(currentUserId.ToString(),entry.id.ToString()) }).ToList(); },c#,linq,C#,Linq,为了显示每个记录的序列号,我只是在每个条目的索引值上加1。如果所有记录都在一页中,上面的代码工作正常。但如果有超过1页,则序列号在第二页中再次从1开始。请帮助我在接下来的几页中继续获得序列号。提前感谢假设分页是在ComplaintEntry级别上完成的(由于ToList()调用,没有其他级别可以进行分页),您需要将初始行号传递给该方法,如下所示: public List<string[]> NotificationManagementData(IEnumerable<Notif
ComplaintEntry
级别上完成的(由于ToList()
调用,没有其他级别可以进行分页),您需要将初始行号传递给该方法,如下所示:
public List<string[]> NotificationManagementData(IEnumerable<NotificationManagements> ComplaintEntry, int currentUserId)
{
return ComplaintEntry.Select((entry, index) => new string[]
{
(index + 1).ToString(),
GetLinks(currentUserId, entry),
entry.state_Id,
entry.refType,
entry.request,
entry.action,
Common.Encrypt(currentUserId.ToString(), entry.id.ToString())
}).ToList();
}
public List NotificationManagementData(IEnumerable completintentry,int currentUserId,int firstRow){
返回completintentry.Select((条目,索引)=>newstring[]{
(索引+第一行).ToString(),
GetLinks(currentUserId,条目),
entry.state\u Id,
entry.refType,
entry.request,
进入。行动,
Common.Encrypt(currentUserId.ToString(),entry.id.ToString())
}).ToList();
}
NotificationManagementData
的调用者知道当前页面,因此他们可以计算出传递给firstRow
参数的内容。分页在哪里发挥作用?我在您的示例代码中没有看到任何提示您正在分页数据的内容。正如@JasonBoyd指出的,我们需要获得有关您如何实现分页的更多信息。在大多数情况下,您需要手动计算[页码]*[每页行数]+索引
,并将其作为参数传入。
public List<string[]> NotificationManagementData(IEnumerable<NotificationManagements> ComplaintEntry, int currentUserId, int firstRow) {
return ComplaintEntry.Select((entry, index) => new string[] {
(index + firstRow).ToString(),
GetLinks(currentUserId, entry),
entry.state_Id,
entry.refType,
entry.request,
entry.action,
Common.Encrypt(currentUserId.ToString(), entry.id.ToString())
}).ToList();
}