Exemplo n.º 1
0
        /// <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 containing the event data.</param>
        private void Page_Load(object sender, System.EventArgs e)
        {
            int currentPage = HnDGeneralUtils.TryConvertToInt(Request["Page"]);

            if (currentPage == 0)
            {
                currentPage = 1;
            }

            if (!Page.IsPostBack)
            {
                plPageListTop.CurrentPage    = currentPage;
                plPageListBottom.CurrentPage = currentPage;

                DataTable results = SessionAdapter.GetSearchResults();
                if (results == null)
                {
                    // no results, redirect to search page
                    Response.Redirect("Search.aspx");
                }

                short pageSize = CacheManager.GetSystemData().PageSizeSearchResults;
                if (pageSize <= 0)
                {
                    pageSize = 50;
                }

                int amountPages = (results.Rows.Count / pageSize);
                if ((amountPages * pageSize) < results.Rows.Count)
                {
                    amountPages++;
                }
                plPageListBottom.AmountPages = amountPages;
                plPageListTop.AmountPages    = amountPages;

                // get the page of the resultset to bind. We page in-memory, so we have to execute the search query just once.
                DataTable toBind = results.Clone();
                for (int i = 0;
                     (i < pageSize) && ((((currentPage - 1) * pageSize) + i) < results.Rows.Count);
                     i++)
                {
                    toBind.ImportRow(results.Rows[((currentPage - 1) * pageSize) + i]);
                }

                rptResults.DataSource = toBind;
                rptResults.DataBind();

                lblAmountThreads.Text = results.Rows.Count.ToString();
                lblSearchTerms.Text   = HttpUtility.HtmlEncode(SessionAdapter.GetSearchTerms());
            }
        }