November 25, 2010

DataPager with sitecore

Here is the procedure to integrate the datapager in sitecore
  1. Add this in the web.config if not exist
    <rendering>
      <typesThatShouldNotBeExpanded>
          <type>System.Web.UI.WebControls.DataPager</type>
      </typesThatShouldNotBeExpanded>
    </rendering>
  2. In the html add the datapage
    <asp:DataPager
     ID="DataPagerRepeater"
     runat="server"
     PagedControlID="ItemsRepeaterType1"
     PageSize="1">
     <Fields>
      <asp:NextPreviousPagerField
       FirstPageImageUrl="/design/twyford/images/paging_first_blue.gif"
       PreviousPageImageUrl="/design/twyford/images/paging_previous_blue.gif"
       ShowFirstPageButton="True"
       ShowPreviousPageButton="True"
       ShowLastPageButton="False"
       ShowNextPageButton="False"
       ButtonCssClass="icons"
       ButtonType="Image" />
    
      <asp:NumericPagerField
       ButtonCount="20" CurrentPageLabelCssClass="current" />
    
      <asp:NextPreviousPagerField
       ShowFirstPageButton="False"
       ShowPreviousPageButton="False"
       ShowNextPageButton="True"
       ShowLastPageButton="True"
       NextPageImageUrl="/design/twyford/images/paging_next_blue.gif"
       LastPageImageUrl="/design/twyford/images/paging_last_blue.gif"
       ButtonCssClass="icons"
       ButtonType="Image"  />
     </Fields>
    </asp:DataPager>
  3. In the ListView add the properties: OnSelectedIndexChanged, OnPagePropertiesChanged and OnPagePropertiesChanging
    <asp:ListView
        ID="ItemsRepeaterType1"
        runat="server"
        OnItemDataBound="ItemsRepeater_ItemDataBound"
        OnSelectedIndexChanged="ItemsRepeaterType1_OnSelectedIndexChanged"
        OnPagePropertiesChanged="ItemsRepeaterType1_PagePropertiesChanged"
        OnPagePropertiesChanging="ItemsRepeaterType1_PagePropertiesChanging"
        >
  4. Example of Page_Load:
    private void Page_Load(object sender, EventArgs e)
    {
     if (!IsPostBack)
     {
      BindData();
     }
    }

2 comments:

  1. Its not working. When Using QuerstringField in Datapager it's taking layout url rather than context item url. Could you please help me in this.

    ReplyDelete
  2. Ok I have invetigate your problem but I am not able to reproduce it. I have create a small video for the step by step for you here: http://www.youtube.com/watch?v=51IhRQ3JLlE&feature=youtu.be

    ReplyDelete