我有一个使用 C# 的 linq 查询,并且想对更改的字段进行排序。该字段是在表中定义为 YYYYMM 的部分日期字段。但是,我希望它在我的转发器中显示为 MM/YYYY,但需要将其排序为 YYYYMM。下面是代码,GrantMonthID 是相关字段。中继器按 MM/YYYY 顺序显示数据。
谢谢你。
var linqQuery = from nn in grantsReceivedDetailList
where (nn.ArrearAuditID == Convert.ToInt32(AdminBasePage.ArrearAuditId))
select
new
{
nn.GrantsReceivedID,
nn.PayeeMPINumber,
Firstname = participantRepository.GetParticipantDetailsbyMemberParticipantIndex(Convert.ToInt32(nn.PayeeMPINumber)).FirstName + " " +
participantRepository.GetParticipantDetailsbyMemberParticipantIndex(Convert.ToInt32(nn.PayeeMPINumber)).LastName,
nn.IVANumber,
GrantMonthID = nn.GrantMonthID.ToString().Substring(4, 2) + "/" + nn.GrantMonthID.ToString().Substring(0, 4),
nn.GrantAmount,
nn.Comments
};
linqQuery = linqQuery.OrderByDescending(y => y.GrantMonthID);
// Execute the linq query and databind
grantListRepeater.DataSource = linqQuery;
grantListRepeater.DataBind();