Wednesday 25 December 2013

Paging With SPDataSource - best paging ever


Paging With SPDataSource (Very Easy)


I give up from SPListItemCollectionPosition and how it works and you have to pay too much attention to last item id and .... even i wrote an article about it you can see it here (paging with splistitemcollectionposition) but not now.


Now i am gonna show you an easy way for paging in very simple steps using SPDataSource


Add Visual Web Part (Contracts)  and on code behind add

 protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (gvContracts != null)
            {
                gvContracts.PagerTemplate = null;
            }
        }

Add SPGridView

  <SharePoint:SPGridView ID="gvContracts" DataSourceID="dsContracts" GridLines="None"
               AutoGenerateColumns="false" 
                 AllowPaging="true" PageSize="2" OnPageIndexChanging="gvContracts_PageIndexChanging"
                    runat="server" ShowHeader="false" OnRowDataBound="gvContracts_RowDataBound">                         <PagerStyle CssClass="gvfooter" />
                    <Columns>
                        <%# Eval("Title")%>
                    </Columns>
                 <PagerSettings Mode="NumericFirstLast" Position="Bottom" />
                </SharePoint:SPGridView>

Add SPDataSource

 <SharePoint:SPDataSource runat="server" ID="dsContracts" DataSourceMode="List">  <SelectParameters>
   <asp:Parameter Name="WebUrl" DefaultValue="/Arabic//TendersAndContracts" />
                        <asp:Parameter Name="ListName" DefaultValue="Contracts" />
                    </SelectParameters>
                </SharePoint:SPDataSource>


run your application and see 

Notes:
you can use it in more complex situations i already did it before.
wothout this line of code (  gvContracts.PagerTemplate = null;)
the pager  will not shown.


this sample image show paging for public portal using this paging with complex search






You are welcomed for any question, just drop me comment.











No comments:

Post a Comment