开发者

ASP.NET: Built-in Gridview Sorting of Generic.List(Of T)

The question is whether built-in sorting of a Generic.List(Of T) is possible. We have a custom gridview that is compiled into its own DLL along with a compiled DLL of classes. Right now, I'm able to get the count by casting a Generic.List to iCollection for paging purposes, but can I create some sort of Sort function that will accept any Generic.List(Of AnyType) and sort accordingly.

I've been able to cast a Generic.List(Of AnyType) to a Generic.List(Of Object), and I think I can cast the objects within that collection to the same type and sort, but I'm not sure if that's possible. My concern now is that I won't be able to cast the objects back to their original type due to the classes being in a compiled state.

Is this a safe assumption, or is it possible to do this? Is it more favorable to simply skip the c开发者_开发知识库ontrol sorting for Generic Lists and simply allow the developer to do the sorting in the event via LINQ or other means.


Generic lists already have Sort (and Count too since it implements ICollection)

    public void Sort();
    public void Sort(IComparer<T> comparer);
    public void Sort(int index, int count, IComparer<T> comparer);
    public void Sort(Comparison<T> comparison);

Why not use those?

public class SomeGridViewWrapper<T>
{
    private List<T> _dataSource;

    public void Sort(Comparison<T> comparison)
    {
        _dataSource.Sort(comparison);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜