开发者

Finding location in list,

开发者 https://www.devze.com 2023-02-05 17:41 出处:网络
In Linq Get items higher then lastname I asked how to get people higher then a certain name. However we use a datagrid with paging and when showing only people higher then lastname \"Jan\", there\'s

In Linq Get items higher then lastname I asked how to get people higher then a certain name.

However we use a datagrid with paging and when showing only people higher then lastname "Jan", there's no way to get back to people starting with AA.

So I was searching for a way to find out on what location the person would have been if following the normal order of selection?

hope this makes sense :)

[edit] 开发者_如何学CThe query type is of EntityQuery. [/edit]


So you want the index of first person record that matches your condition?

var index = query.TakeWhile(person => person.LastName.CompareTo(name) < 0).Count();

This counts the number of elements that match the condition and the returned value is the index of the first element that does not match with the condition.

Just note that you must negate the condition that you used with Where() as in this case TakeWhile() is used to get the items that you don't want.


Manage to solve this problem using the example given at Getting to certain member using datapager and datagrid

0

精彩评论

暂无评论...
验证码 换一张
取 消