我正在实施自定义排序&寻找我的gridview。令我感到困惑的是
答案 0 :(得分:1)
是,
你必须指定selectmethod,CountMethod,Select Paramenter,SorExpression,Type name。
在select方法中,您必须在触发查询的位置提供静态 - 共享方法名称。
<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()));
}
}