number of search results per page
Hi
I want to display number of search results per page based on a dropdown selection on search results page, how can i do it ? please see the attached image.
Please see my code below
SearchResultsTemplate.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchResultsTemplate.ascx.cs" Inherits="AA.Sitefinity.Web.UserControls.Search.SearchResultsTemplate" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity.Search.Impl" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
<asp:Label runat="server" ID="SearchTerms"></asp:Label><br /><br />
<sfSearch:SearchBox ID="topSearchBox" runat="server" />
<sitefinity:SitefinityLabel id="resultsStats" runat="server" WrapperTagName="p" CssClass="sfsearchResultStatistics" Text="<%$Resources:SearchResources, SearchResultsStatusMessage %>" Visible="false"/>
<asp:Label ID="lblItemsPerPage" runat="server"></asp:Label>
<asp:DropDownList runat="server" ID="ddlItemsPerPage" OnSelectedIndexChanged="ddlItemsPerPage_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
<asp:ListItem Text="10" Value="10"></asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:Label runat="server" ID="ItemsPerPageLabel" Visible="false"/>
<asp:Repeater ID="resultsList" runat="server" OnItemDataBound="resultsList_ItemDataBound" >
<HeaderTemplate>
<dl class="sfsearchResultsWrp sfsearchReultTitleSnippetUrl">
</HeaderTemplate>
<ItemTemplate>
<div style="border-bottom:dotted 1px; border-bottom-color:grey; padding-bottom:20px;">
<div>
<b><a id="TitleLink" runat="server" href='<%# Eval("Link")%>'><%# Eval("Title") %></a></b><br />
<%--<p><%# Eval("Summary")%></p>--%>
<p><%# Eval("HighLighterResult")%></p>
<a id="URLLink" runat="server" href='<%# Eval("Link")%>'><%# Eval("Link")%></a><br />
</div>
<div style="border:1px dotted grey;">
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</dl>
</FooterTemplate>
</asp:Repeater>
<sitefinity:Pager ID="pager" runat="server" ShowFirstAndLast="true" PageSize="3" />
<sfSearch:SearchBox ID="bottomSearchBox" runat="server" Visible="false" />
=============================================================================
SearchResultsTemplate.ascx.cs
namespace AA.Sitefinity.Web.UserControls.Search
public partial class SearchResultsTemplate : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)
bottomSearchBox.Visible = false;
resultsStats.Visible = false;
//ItemsPerPageLabel.Visible = false;
//pager.PageSize = Convert.ToInt32(ddlItemsPerPage.SelectedItem.Value);
protected void resultsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
if(e.Item.ItemType == ListItemType.Item)
var myitem = e.Item.DataItem as IDocument;
var type = myitem.GetValue("ContentType");
switch (type)
case "Telerik.Sitefinity.Libraries.Model.Video" :
break;
case "Telerik.Sitefinity.Libraries.Model.Image" :
break;
protected void ddlItemsPerPage_SelectedIndexChanged(object sender, EventArgs e)
pager.PageSize = Convert.ToInt32(ddlItemsPerPage.SelectedItem.Value);
===============================================================================
CustomSearchResults.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Sitefinity.Services.Search.Web.UI.Public;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Services.Search;
using System.Web.UI;
using System.ComponentModel;
namespace AA.Sitefinity.Web.UserControls.Search
public class CustomSearchResults : SearchResults
public CustomSearchResults()
this.AllowPaging = true;
//this.ItemsPerPage = Convert.ToInt32(this.ddlItemsPerPage.SelectedItem.Value);
this.LayoutTemplatePath = CustomSearchResults.layoutTemplatePath;
//this.SearchFields = new[] "Title", "Content" ;
//this.HighlightedFields = new[] "Title", "Content" ;
protected internal virtual Label ItemsPerPageLabel
get
return this.Container.GetControl<Label>("ItemsPerPageLabel", false);
protected internal virtual Label SearchTerms
get
return this.Container.GetControl<Label>("SearchTerms", false);
protected internal virtual DropDownList ddlItemsPerPage
get
return this.Container.GetControl<DropDownList>("ddlItemsPerPage", false);
protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
base.InitializeControls(container);
if (!string.IsNullOrEmpty(this.Query))
int totalItems = 0;
//this.Pager.PageSize = 3;
if (!string.IsNullOrEmpty(this.PageKey))
this.Pager.CurrentPage = Convert.ToInt32(this.PageKey);
if (ddlItemsPerPage!=null)
this.Pager.PageSize = Convert.ToInt32(ddlItemsPerPage.SelectedItem.Value);
this.Pager.DisplayCount = Convert.ToInt32(ddlItemsPerPage.SelectedItem.Value);
if (this.AllowPaging)
this.ItemsPerPage = this.Pager.PageSize;
var take = this.Pager.PageSize;
var skip = (this.Pager.CurrentPage - 1) * this.Pager.PageSize;
var searcher = this.GetSearcher();
var result = searcher.Search(this.Query, this.IndexCatalogue, skip, take, out totalItems);
var itemsOnPage = this.Pager.PageSize; //this.ItemsPerPage.ToString();
// var searchResultsCount = this.ResultsStats;
var itemsCount = result.ToList().Count.ToString();
this.ItemsPerPageLabel.Text = string.Format("Displaying results 1-0 of 1", itemsOnPage, itemsCount);
this.SearchTerms.Text = "Your Search for \"" + this.Query + "\" returned " + totalItems.ToString() + " results";
public static readonly string layoutTemplatePath = "~/UserControls/Search/SearchResultsTemplate.ascx";
thanks
Anil
Hello,
To change the items per page you need to go to click the edit button on the Search results widget. Select advanced and change the value in the screenshot below:
http://screencast.com/t/3OrQ73mGu1X
By default it is set to 10.
To extend the search I would suggest you to review these blog posts where you could find useful information which will help you to customize your search the way you want:
www.sitefinity.com/.../extending-sitefinity-search-and-searching-by-category
http://www.sitefinity.com/blogs/boyan-barnevs-blog-/2012/11/06/customizing-sitefinity-searchresults---displaying-product-thumbnails-and-other-content-type-specific-data
http://www.sitefinity.com/blogs/teamblog/posts/team-blog/2012/02/06/hiding_page_content_from_the_search_engine_in_sitefinity_using_layout_widgets
Regards,
Stefani Tacheva
Telerik