SharePoint中列表数据的分页
最近在研究微软Office系列的SharePoint2007,在感受到强大定制化功能的同时,也感受到MOSS对开发者带来的一些困扰。特别是当一个List中存有大量数据的时候,MOSS并没有提供现有的方法可以支持分页取集,Google了一下老外们的文章,居然也没有找到有用的资料。没有办法,只有自己动手!
思路还是T-SQL的思路,Select top N * From Table where ID not in (Select top M ID From Table)
下面是代码:
/**//// <summary>
/// 根据栏目分页取新闻
/// </summary>
/// <param name="MenuId">栏目序号</param>
/// <param name="PageSize">页长</param>
/// <param name="PageNo">页数</param>
/// <param name="ListName">表名</param>
/// <returns></returns>
public SPListItemCollection GetNewsByMenuId(int MenuId, uint PageSize, int PageNo,string ListName)
{
using (SPWeb myweb = SPContext.Current.Web)
{
int MinId = 9999999; //设定最大ID初始值
string queryStr;
if (PageNo > 1)
{
queryStr = "select ID From " + ListName + " where MenuID = " + MenuId + " Order By ID DESC";
FriendlyQuery tempQuery = new FriendlyQuery(myweb, queryStr);
tempQuery.Scope = FriendlyQuery.QueryScope.AllItems;
tempQuery.RowLimit = PageSize * uint.Parse(Convert.ToString(PageNo - 1));
SPListItemCollection tempResult = tempQuery.GetItems();
if (tempResult.Count > 0)
{
for (int i = 0; i < tempResult.Count; i++)
{
if (Int32.Parse(tempResult["ID"].ToString()) < MinId)
{
MinId = Int32.Parse(tempResult["ID"].ToString());
}
}
}
}
queryStr = "Select * From "+ListName+" where MenuID = "+MenuId+" andID <" + MinId + " Order By ID DESC";
FriendlyQuery query = new FriendlyQuery(myweb, queryStr);
query.Scope = FriendlyQuery.QueryScope.AllItems;
query.RowLimit = PageSize;
SPListItemCollection result = query.GetItems();
return result;
}
}
经测试功能是实现了,但是性能还没有进行测试。性能测试的数据稍后放出。
页:
[1]