自定义分页&排序网格视图

发布于 2024-12-20 05:22:12 字数 105 浏览 2 评论 0原文

我正在实施自定义排序和我的 gridview 的分页。让我困惑的是,

  1. 为什么我们必须指定对象数据源的过滤列和过滤列?总计计数方法中过滤列值(选择参数) ?

I am implementing custom sorting & paging for my gridview. On thing that baffles me is that

  1. Why do we have to specify object datasource's filter column & filter column value (select parameters) in the total count method ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演出会有结束 2024-12-27 05:22:13

是的,

您必须指定 selectmethod、CountMethod、Select Paramenter、SorExpression、Type name。

在选择方法中,您必须在触发查询的地方提供静态 - 共享方法名称。

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"

  EnablePaging="true" OnSelecting="ObjectDataSource1_Selecting"

  TypeName="WebApplication1.MinimalObjectDataSourceObject"

  SelectMethod="MinimalSelectMethod" SelectCountMethod="MinimalSelectCountMethod" />

类别声明

public class MinimalObjectDataSourceObject
{
    // A nice list for demonstration purposes.
    private static List<CultureInfo> baseList = new List<CultureInfo>(CultureInfo.GetCultures(CultureTypes.AllCultures));

    // Our minimal SelectMethod.

    public static List<CultureInfo> MinimalSelectMethod(string parameter1, string parameter2, int startRowIndex,
        int maximumRows)
    {
        List<CultureInfo> someList = GetSomeKindOfList(parameter1, parameter2);
        // Make sure we don't try to get objects that don't exist, ArgumentOutOfRangeException otherwise!
        if (startRowIndex + maximumRows > someList.Count)
        {
            maximumRows = someList.Count - startRowIndex;
        }

        return someList.GetRange(startRowIndex, maximumRows);
    }

    // Our minimal SelectCountMethod.

    public static int MinimalSelectCountMethod(string parameter1, string parameter2)
    {
        return GetSomeKindOfList(parameter1, parameter2).Count;
    }


    // A method to get a filtered list for our primary data source.

    public static List<CultureInfo> GetSomeKindOfList(string parameter1, string parameter2)
    {
        return baseList.FindAll(x => x.EnglishName.ToLower().StartsWith(parameter1))
            .FindAll(x => string.IsNullOrEmpty(parameter2.ToLower()) ||
                          x.EnglishName.ToLower().EndsWith(parameter2.ToLower()));
    }
}

yes,

you have to specify selectmethod, CountMethod, Select Paramenter, SorExpression, Type name.

In select method you have to give Static - shared Method name where you have fired the query.

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"

  EnablePaging="true" OnSelecting="ObjectDataSource1_Selecting"

  TypeName="WebApplication1.MinimalObjectDataSourceObject"

  SelectMethod="MinimalSelectMethod" SelectCountMethod="MinimalSelectCountMethod" />

CLASS DECLARATION

public class MinimalObjectDataSourceObject
{
    // A nice list for demonstration purposes.
    private static List<CultureInfo> baseList = new List<CultureInfo>(CultureInfo.GetCultures(CultureTypes.AllCultures));

    // Our minimal SelectMethod.

    public static List<CultureInfo> MinimalSelectMethod(string parameter1, string parameter2, int startRowIndex,
        int maximumRows)
    {
        List<CultureInfo> someList = GetSomeKindOfList(parameter1, parameter2);
        // Make sure we don't try to get objects that don't exist, ArgumentOutOfRangeException otherwise!
        if (startRowIndex + maximumRows > someList.Count)
        {
            maximumRows = someList.Count - startRowIndex;
        }

        return someList.GetRange(startRowIndex, maximumRows);
    }

    // Our minimal SelectCountMethod.

    public static int MinimalSelectCountMethod(string parameter1, string parameter2)
    {
        return GetSomeKindOfList(parameter1, parameter2).Count;
    }


    // A method to get a filtered list for our primary data source.

    public static List<CultureInfo> GetSomeKindOfList(string parameter1, string parameter2)
    {
        return baseList.FindAll(x => x.EnglishName.ToLower().StartsWith(parameter1))
            .FindAll(x => string.IsNullOrEmpty(parameter2.ToLower()) ||
                          x.EnglishName.ToLower().EndsWith(parameter2.ToLower()));
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文