预先:
我正在使用一个无法更改的静态数据库,因为它被外部软件使用。
如果它不是“1”或“6”,我将数据库值从 StatusTypeId 映射到这些值之间的值。背景:支持票务系统
客户应该只看到 StatusTypeIds 1、3 和 6。1(打开)、3(工作中)、6(关闭)
所以我手动更改了网格值,现在正在进行正确的排序。
在 EntityDataSource 上执行的初始排序表达式工作正常,直到使用网格的排序功能。然后,无论我手动截取,排序都做错了。
EntityDataSource 的初始排序:
<asp:EntityDataSource ID="DefectsDataSource" runat="server"
ConnectionString="name=*" DefaultContainerName="*"
EnableFlattening="False" EntitySetName="Defects" Select="it.[DefectId], it.[Name], it.[StatusTypeId]"
OrderBy="(CASE WHEN it.[StatusTypeId] <> 1 AND it.[StatusTypeId] <> 6 THEN 2 ELSE it.[StatusTypeId] END)"/>
是否可以从 Grid(SortCommand 事件)中获取请求的排序顺序并将 EntityDataSource 的 OrderBy 属性设置为正确排序?我试过了,但它被忽略了。
SortCommand 事件的实现:
protected void SortCommand(object sender, GridSortCommandEventArgs e)
{
if (e.SortExpression == "StatusTypeId")
{
string sortExpression = (e.NewSortOrder == GridSortOrder.Ascending) ? "ASC" : e.NewSortOrder == GridSortOrder.Descending ? "DESC" : "";
this.DefectsDataSource.OrderBy = string.Format("(CASE WHEN it.[StatusTypeId] <> 1 AND it.[StatusTypeId] <> 6 THEN 2 ELSE it.[StatusTypeId] END) {0}", sortExpression);
this.RadGrid.Rebind();
}
}
我希望有足够的信息来帮助我。如果我错过了什么,请问我。