sharepoint实现假分页

SPSecurity.RunWithElevatedPrivileges(delegate

            {

                using (var site = new SPSite(StrUrl))

                {

                    #region 增加公告



                    using (SPWeb web = site.OpenWeb())

                    {

                        var dt = new DataTable();

                        dt.Columns.Add( "Title", typeof (string));

                        dt.Columns.Add( "Author", typeof (string));

                        dt.Columns.Add( "Created", typeof (DateTime));

                        dt.Columns.Add( "PostType", typeof (string));

                        dt.Columns.Add( "IsSendMail", typeof (string));

                        SPList spList = web.Lists["公告" ];

                        SPListItemCollection itemColl = spList.GetItems();

                        var objPds = new PagedDataSource();

                        objPds.DataSource = itemColl;

                        objPds.AllowPaging = true;

                        objPds.PageSize = 10;

                        int CurPage;

                        if (Request.QueryString["Page" ] != null)

                            CurPage = Convert.ToInt32(Request.QueryString["Page" ]);

                        else

                            CurPage = 1;

                        objPds.CurrentPageIndex = CurPage - 1;

                        lblCurrentPage.Text = "当前页:" + CurPage;

                        if (!objPds.IsFirstPage)

                            lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" +

                                                  Convert.ToString(CurPage - 1);

                        if (!objPds.IsLastPage)

                            lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" +

                                                  Convert.ToString(CurPage + 1);

                        foreach (SPListItem item in objPds)

                        {

                            string title = item.Title;

                            string tistle = item.Title;

                            //string title = "标题";

                            string author =

                                item[ "Author"].ToString().Substring(item["Author" ].ToString().LastIndexOf("#") + 1);

                            DateTime create = Convert .ToDateTime(item["PublishedDate"]);

                            string postType =

                                item[ "PostCategory"].ToString()

                                    .Substring(item[ "PostCategory"].ToString().LastIndexOf("#" ) + 1);

                            string isSendMail = Convert .ToBoolean(item["IsSendMail"]) ? "是" : "否" ;

                            dt.Rows.Add(title, author, create, postType, isSendMail);

                        }



                        #endregion



                        //绑定

                        PostRepeater.DataSource = dt;

                        PostRepeater.DataBind();

                    }

                }

                ;

            });


<div class="rightmid">

            <asp: Repeater ID ="PostRepeater" runat ="server">

                <HeaderTemplate>

                    <table class="gridtable" width="100%">

                        <tr <% --width="100%"--%>>

                            <th width="20%"> 标题</th >

                            <th width="20%"> 创建者</th >

                            <th width="20%"> 发布时间</th >

                            <th width="20%"> 公告类型</th >

                            <th width="20%"> 发送邮件</th >

                        </tr>

                </HeaderTemplate>



                <ItemTemplate>

                    <tr>

                        <td> <%#Eval("Title") %></ td>

                        <td> <%#Eval("Author") %></ td>

                        <td> <%#Eval("Created", "{0:yyyy-MM-dd}") %></td >

                        <td> <%#Eval("PostType") %></ td>

                        <td> <%#Eval("IsSendMail") %></ td>

                    </tr>

                </ItemTemplate>



                <FooterTemplate>

                    </table>

                </FooterTemplate>

            </asp: Repeater>

            <div style=" padding: 5px ; background-color: #dedede;text-align : center">

                <asp: Label ID ="lblCurrentPage" runat ="server"></asp: Label>

                <asp: HyperLink ID ="lnkPrev" runat ="server">上一页</ asp:HyperLink >

                <asp: HyperLink ID ="lnkNext" runat ="server">下一页</ asp:HyperLink >

            </div>

        </div>

  

你可能感兴趣的:(SharePoint)