[英]GridView and Linq Query sorting
I'm using a Linq
Query to populate a GridView
. 我正在使用
Linq
查询来填充GridView
。
Then I set it to the Datasource
. 然后,将其设置为
Datasource
。
In the sorting event, I'd like to retrieve the the anonymous type that the query generates and find the members name. 在排序事件中,我想检索查询生成的匿名类型并找到成员名称。
Is it possible to do so ? 有可能这样做吗?
Here's an exemple of the query 这是查询的一个例子
var q = from inboundCall in dc.GetTable<InboundCall>()
join employee in dc.GetTable<Employee>() on inboundCall.EmployeeID equals employee.ID
join code in dc.GetTable<Code>() on inboundCall.CodeID equals code.ID
join site in dc.GetTable<Site>() on inboundCall.SiteID equals site.ID
where inboundCall.IsSuccess == true
select new
{
EmployeeNumber = employee.Number,
EmployeeName = employee.Name,
CallerID = inboundCall.CallerID,
SiteName = site.Name,
CallDate = inboundCall.CallDate,
CodeName = code.Name
};
And then 接着
gridData.DataSource = q;
What can I do in the sorting event to retieve the Anonymous type and do something like that 在排序事件中我可以做些什么来恢复匿名类型并做类似的事情
employeeList.Sort((x, y) => ((Int32)x.GetType().GetProperty(e.SortExpression).GetValue(x, null)).CompareTo((Int32)y.GetType().GetProperty(e.SortExpression).GetValue(y, null)) * sortValue);
You could do this with reflection, or you could use the dynamic LINQ library to add the OrderBy clause. 您可以通过反射来执行此操作,也可以使用动态LINQ库添加OrderBy子句。
Or, a better option may be to create an actual class / struct that represents the data you will be retrieving. 或者,更好的选择可能是创建一个实际的类/结构,以表示您将要检索的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.