直接使用objectdatasourse分頁技術是低效了,它直接加載所有的數據然後與listview或gridview綁定。今天我們要使用新的方法來改進這種低效的方法。
改用高效的分頁技術。高效分頁技術的文章網上有好多這裏不再從新介紹使用了。我要講的三層模式裏面如何使用高效分頁。在三層裏面通過objectdatasourse類中方法
,在那個類裏面分別需要兩個方法一個獲取總頁數一個獲取結果集。這個兩個方法是相輔相成的,缺一不可,不然會報錯。假如你要使用一個方法來獲取數據集例
public List<RelationUserRole> selectUserRolePaginListByRoleId(int roleId,int maximumRows, int startRowIndex)
//roleId是過濾條件之一 maximumRows頁面展示數據條數startRowIndex是當前頁開始行數
{return relationServer.GetPagingRelationUserRleListByRole( startRowIndex, maximumRows, roleId);
}
public int QueryUserRoleCount(int roleId)
//返回所有記錄行數總數roleId是過濾條件
{
int result = relationServer.GetAllUserRoleCount(roleId);
return result>0?result:0;
}
這兩個方法要一起使用單一使用就會出錯
也就是說在使用
ODSUserRole.SelectMethod = "selectUserRolePaginListByRoleId";
ODSUserRole.SelectParameters.Add(new Parameter("roleId"));
ODSUserRole.SelectParameters["roleId"].DefaultValue = "1";
ODSUserRole.SelectParameters["roleId"].Type = TypeCode.Int32;
時也要設置使用ODSUserRole.SelectCountMethod="QueryUserRoleCount";
不然就會出錯