2011-12-08 18 views
0

私はカスタム並べ替え&私のgridviewのページングを実装しています。私をバッフルの事で私達が総カウント方法でオブジェクトデータソースのフィルターカラム&フィルターカラム値(選択パラメータ)を指定しなければならないのはなぜカスタムページングと並べ替えgridview

  1. ということでしょうか?

答えて

1

はい、

あなたはselectmethod、CountMethod、選択Paramenter、SorExpression、タイプ名を指定する必要があります。

選択メソッドでは、クエリを起動した場所の静的共有メソッド名を指定する必要があります。

<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())); 
    } 
} 
関連する問題