Asp.net 定制寻呼&;排序网格视图

Asp.net 定制寻呼&;排序网格视图,asp.net,objectdatasource,Asp.net,Objectdatasource,我正在为我的gridview实现自定义排序和分页。让我困惑的是 为什么我们必须在total count方法中指定对象数据源的筛选列和筛选列值(选择参数) 对 您必须指定selectmethod、CountMethod、SelectParameter、SorExpression、Type name 在select方法中,您必须在触发查询的位置提供静态共享方法名 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" Ena

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

  • 为什么我们必须在total count方法中指定对象数据源的筛选列和筛选列值(选择参数)
  • 您必须指定selectmethod、CountMethod、SelectParameter、SorExpression、Type name

    在select方法中,您必须在触发查询的位置提供静态共享方法名

    <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()));
        }
    }
    
    公共类MinimalObjectDataSourceObject
    {
    //一个很好的列表,用于演示。
    私有静态列表baseList=新列表(CultureInfo.GetCultures(CultureTypes.AllCultures));
    //我们的最小选择方法。
    公共静态列表最小选择方法(字符串参数1、字符串参数2、int startRowIndex、,
    int最大值(行)
    {
    List someList=GetSomeKindOfList(参数1,参数2);
    //确保我们不尝试获取不存在的对象,否则ArgumentOutOfRangeException!
    如果(startRowIndex+maximumRows>someList.Count)
    {
    maximumRows=someList.Count-startRowIndex;
    }
    返回someList.GetRange(startRowIndex,maximumRows);
    }
    //我们的最小选择计数法。
    公共静态int-MinimalSelectCountMethod(字符串参数1、字符串参数2)
    {
    返回GetSomeKindOfList(参数1,参数2);
    }
    //获取主要数据源的筛选列表的方法。
    公共静态列表GetSomeKindOfList(字符串参数1,字符串参数2)
    {
    返回baseList.FindAll(x=>x.EnglishName.ToLower().StartsWith(参数1))
    .FindAll(x=>string.IsNullOrEmpty(参数2.ToLower())||
    x、 EnglishName.ToLower().EndsWith(参数2.ToLower());
    }
    }