在基于Ajax搜索的Web控件上实现分页功能

我目前正在使用带updatemode条件的UpdatePanel构建搜索功能。 这个updatepanel的触发器是我的searchPhrase TextBox。 当TextChanged触发时,我的面板得到更新并显示正确的搜索结果。 然而,我不知道如何实现分页功能,它可以处理我的搜索结果。 我希望在部分页面更新中显示分页链接,并且我希望分页器也更新我的searchResults(只想在一个页面上显示3个结果)。 我如何正确设置它?

这是我的代码(ascx)




    <div class="filterBox">
        <asp:PlaceHolder ID="filterOnePlaceholder"

RUNAT = “服务器”>

    <div class="filterBox">
        <asp:PlaceHolder ID="filterTwoPlaceholder"

runat =“server”> PaginaMarker DIV:

    <script type="text/javascript">
        function ClientCallbackFunction(args)
        {

        }
    </script> 


    <asp:Button ID="btnBackwards" Text="Vorige"

OnClick =“MyServerCall(this.value)”/>

    <asp:DropDownList ID="DropDownListChoice" runat="server"

onChange =“MyServerCall(this.value)”>选择1选择2选择3选择4

(CS)

//需要存储searchResults列表validSearchResults = new List();

    private List<string> listOneSelectedItems = new

名单(); 私人列表listTwoSelectedItems =新列表();

    private string currentCategoryPath = string.Empty;

    private string _callbackArgs;


    /// <summary>
    /// Raises the <see cref="E:System.Web.UI.Control.Init"/>

事件。 /// ///包含事件数据的对象。 protected override void OnInit(EventArgs e){base.OnInit(e);

        this.UpdateSelectedItemLists();
        this.currentCategoryPath = Sitecore.Context.Item.Paths.FullPath;

        this.searchPhrase.TextChanged += new

事件处理程序(searchPhrase_TextChanged);

        this.filterOneCbl.SelectedIndexChanged

+ =新的EventHandler(filterOneCbl_SelectedIndexChanged); this.filterTwoCbl.SelectedIndexChanged + = new EventHandler(filterTwoCbl_SelectedIndexChanged); this.ProductRepeater.ItemDataBound + = new RepeaterItemEventHandler(ProductRepeater_ItemDataBound); }

    private void UpdateScreen()
    {
        // update the list of selectedItems for use with the

从索引中选择新的项目this.UpdateSelectedItemLists(); this.GetSearchResults();

        ProductRepeater.DataSource = validSearchResults;
        ProductRepeater.DataBind();

        ProductenUpdate.Update();
    }

    void btnSearch_Click(object sender, EventArgs e)
    {
        // update the list of selectedItems for use with the

从索引中选择新的项目this.UpdateSelectedItemLists(); this.GetSearchResults();

        ProductRepeater.DataSource = validSearchResults;
        ProductRepeater.DataBind();

        ProductenUpdate.Update();
    }

    private void ProductRepeater_ItemDataBound(object

sender,RepeaterItemEventArgs e){Item dataItem =(Item)e.Item.DataItem;

        // if there is a dataItem
        if (dataItem != null)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType

== ListItemType.Item){Sitecore.Web.UI.WebControls.Text Titel =(Sitecore.Web.UI.WebControls.Text)e.Item.FindControl(“Titel”); Sitecore.Web.UI.WebControls.Text Auteur =(Sitecore.Web.UI.WebControls.Text)e.Item.FindControl(“Auteur”); Sitecore.Web.UI.WebControls.Text Intro =(Sitecore.Web.UI.WebControls.Text)e.Item.FindControl(“Intro”); Sitecore.Web.UI.WebControls.Image Thumb =(Sitecore.Web.UI.WebControls.Image)e.Item.FindControl(“Thumb”);

                if (Thumb != null)
                {
                    Thumb.Item = dataItem;
                }

                if (Titel != null)
                {
                    Titel.Item = dataItem;
                }

                if (Auteur != null)
                {
                    Auteur.Item = dataItem;
                }

                if (Intro != null)
                {
                    Intro.Item = dataItem;
                }
            }
        }            
    }

    /// <summary>
    /// Handles the TextChanged event of the searchPhrase control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance

包含事件数据。 private void searchPhrase_TextChanged(object sender,EventArgs e){this.UpdateScreen(); }

    /// <summary>
    /// Handles the SelectedIndexChanged event of the

filterTwoCbl控制。 /// ///事件的来源。 ///包含事件数据的实例。 private void filterTwoCbl_SelectedIndexChanged(object sender,EventArgs e){this.UpdateScreen(); }

    /// <summary>
    /// Handles the SelectedIndexChanged event of the

filterOneCbl控件。 /// ///事件的来源。 ///包含事件数据的实例。 private void filterOneCbl_SelectedIndexChanged(object sender,EventArgs e){this.UpdateScreen(); }

    /// <summary>
    /// Updates the selected item lists.
    /// </summary>
    private void UpdateSelectedItemLists()
    {
        foreach (ListItem thisItem in filterOneCbl.Items)
        {
            if (thisItem.Selected)
            {
                if (!listOneSelectedItems.Contains(thisItem.Value.ToUpper()))
                {
                    listOneSelectedItems.Add(thisItem.Value.ToUpper());
                }
            }
        }

        foreach (ListItem thisItem in filterTwoCbl.Items)
        {
            if (thisItem.Selected)
            {
                if (!listTwoSelectedItems.Contains(thisItem.Value.ToUpper()))
                {
                    listTwoSelectedItems.Add(thisItem.Value.ToUpper());
                }
            }
        }
    }

    /// <summary>
    /// Gets the search results.
    /// </summary>
    private void GetSearchResults()
    {
        SearchResultRetreiver retriever = new

SearchResultRetreiver( “productenSearch”); IndexSearcher搜索器= null;

        Hits mySearchResults =  retriever.GetSearchResults(searchPhrase.Text.Trim(),

ref搜索者);

        if (mySearchResults != null)
        {
            for (int i = 0; i < mySearchResults.Length(); i++)
            {
                Item newItem = Sitecore.Data.Indexing.Index.GetItem(mySearchResults.Doc(i),

Sitecore.Context.Database); string itemTitel = SitecoreHelper.ShowItemTitel(newItem); bool addItem = true; if(itemTitel.StartsWith(“$”))addItem = false; if(itemTitel.StartsWith(“_”))addItem = false;

                if (addItem)
                {
                    this.validSearchResults.Add(newItem);
                }
            }
        }
    }

    private void FilterSearchResults()
    {



    }

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance

包含事件数据。 protected void Page_Load(object sender,EventArgs e){Item contextItem = Sitecore.Context.Item; Item subwebsiteItem = contextItem.Axes.GetAncestors()。其中​​(c => c.Axes.Level == 4).FirstOrDefault();

        Sitecore.Data.Fields.CheckboxField

filterOneSelected = subwebsiteItem.Fields [“Filter1Actief”]; Sitecore.Data.Fields.CheckboxField filterTwoSelected = subwebsiteItem.Fields [“Filter2Actief”];

        if (filterOneSelected.Checked)
        {
            TitelTwo.Item = subwebsiteItem;
        }

        if (filterTwoSelected.Checked)
        {
            TitelOne.Item = subwebsiteItem;
        }

        if (!Page.IsPostBack)
        {
            string callbackRef = Page.ClientScript.GetCallbackEventReference(this,

“args”,“ClientCallbackFunction”,“”);

            string callbackScript = "function MyServerCall(args)" +
                "{" + callbackRef + "}";

            Page.ClientScript.RegisterClientScriptBlock(this.GetType(),

“MyServerCall”,callbackScript,true);

            filterOnePlaceholder.Visible = false;
            filterTwoPlaceholder.Visible = false;

            if (subwebsiteItem != null)
            {                   
                if (filterOneSelected.Checked)
                {
                    filterOnePlaceholder.Visible = true;  


                    Item filterOneLocation =

Sitecore.Context.Database.GetItem(subwebsiteItem.Paths.FullPath +“/ Filters / Filter1”); 列表filterOneList = new List();

                    filterOneList = filterOneLocation.GetChildren().Where(c

=> c.TemplateName.ToLower()==“filter”)。ToList();

                    foreach (Item filterItem in filterOneList)
                    {
                        ListItem thisItem = new

ListItem(filterItem [“Naam”],filterItem.ID.ToGuid()。ToString()); this.filterOneCbl.Items.Add(thisItem); }}

                if (filterTwoSelected.Checked)
                {
                    filterTwoPlaceholder.Visible = true;

                    Item filterTwoLocation =

Sitecore.Context.Database.GetItem(subwebsiteItem.Paths.FullPath +“/ Filters / Filter2”); List filterTwoList = new List();

                    filterTwoList = filterTwoLocation.GetChildren().Where(c

=> c.TemplateName.ToLower()==“filter”)。ToList();

                    foreach (Item filterItem in filterTwoList)
                    {
                        ListItem thisItem = new

ListItem(filterItem [“Naam”],filterItem.ID.ToGuid()。ToString()); this.filterTwoCbl.Items.Add(thisItem); }}}}
}

    #region ICallbackEventHandler Members

    /// <summary>
    /// Returns the results of a callback event that targets a control.
    /// </summary>
    /// <returns>The result of the callback.</returns>
    public string GetCallbackResult()
    {
        return this._callbackArgs;
    }

    /// <summary>
    /// Processes a callback event that targets a control.
    /// </summary>
    /// <param name="eventArgument">A string that

表示传递给事件处理程序的事件参数。 public void RaiseCallbackEvent(string eventArgument){this._callbackArgs = eventArgument; }

请看一看,并告诉我如何让我的解决方案为寻呼机工作。


我通过引入一个GetList()方法和一个在彼此之后被调用的Update()方法来解决这个问题。 在de GetList()方法我会设置项目的总量,并在更新方法,然后我会调用另一个方法,将创建寻呼机。 这解决了我的问题。

链接地址: http://www.djcxy.com/p/7605.html

上一篇: Implementing Paging functionaliteit on a Ajax search based Webcontrol

下一篇: Custom C# HttpModule Infinite Redirect Loop