直接使用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";
不然就会出错