gpt4 book ai didi

c# - 显示 DataTable 中记录的序列号和数据绑定(bind)是通过 LINQ 完成的

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:40 25 4
gpt4 key购买 nike

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();
}

为了显示每条记录的序列号,我只是将每个条目的索引值加 1。如果所有记录都在一页中,上面的代码工作正常。但是如果有超过 1 页,序列号再次从第二页的 1 开始。请帮助我在下一页中继续获取序列号。提前致谢

最佳答案

假设分页是在 ComplaintEntry 级别完成的(没有其他级别可以这样做,因为 ToList() 调用)你需要将初始行号传递给方法,像这样:

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();
}

NotificationManagementData 的调用者知道当前页面,因此他们可以计算出要传递给 firstRow 参数的内容。

关于c# - 显示 DataTable 中记录的序列号和数据绑定(bind)是通过 LINQ 完成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48506236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com