路人甲之碎语
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
给我留言
查看留言
我的标签
SharePoint
(1)
分页
(1)
Paging
(1)
随笔档案
2008年7月 (1)
最新评论
1. re: SharePoint中列表数据的分页
偶都是直接webPart了.
--小牛大牛
Powered by:
博客园
模板提供:
沪江博客
博客园
|
首页
|
发新随笔
|
发新文章
|
联系
|
订阅
|
管理
2008年7月9日
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[i][
"
ID
"
].ToString())
<
MinId)
{
MinId
=
Int32.Parse(tempResult[i][
"
ID
"
].ToString());
}
}
}
}
queryStr
=
"
Select * From
"
+
ListName
+
"
where MenuID =
"
+
MenuId
+
"
and ID <
"
+
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;
}
}
经测试功能是实现了,但是性能还没有进行测试。性能测试的数据稍后放出。
小弟第一次发贴,水平很烂,还望各位仁兄多指教。
posted @
2008-07-09 08:38
根号贰 阅读(972) |
评论 (9)
|
编辑