protected void Page_Load(object sender, EventArgs e) { string eventTarget = Request["__EVENTTARGET"]; if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions")) { string pageSizeOption = Request.QueryString["ps"]; if (!string.IsNullOrEmpty(pageSizeOption)) { PageSizeOptions.ClearSelection(); ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption); if (item != null) { item.Selected = true; } } } else if (eventTarget.EndsWith("PageSizeOptions")) { string url = Request.RawUrl; if (url.Contains("?")) { url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?")); } url += "?s=" + SortResults.SelectedValue; url += "&ps=" + PageSizeOptions.SelectedValue; Response.Redirect(url); } _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue); SetPagerIndex(); CatalogNodeList.RepeatColumns = Cols; if (IsValidCategory()) { //INITIALIZE THE CONTENT NODES _ContentNodes = new List <Product>(); List <Product> visibleNodes = (List <Product>)ProductDataSource.LoadForCategory(true, this.CategoryId, false, true, SortResults.SelectedValue, _pageSize, (_HiddenPageIndex * _pageSize)); // CUSTOM SORTING ON VOLUME PRICES if (SortResults.SelectedValue.Equals("Price ASC")) { visibleNodes = visibleNodes.OrderBy(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.First().DiscountAmount : x.Price).ThenBy(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.Last().DiscountAmount : 0).ToList(); //Lowest-Highest } else if (SortResults.SelectedValue.Equals("Price DESC")) { visibleNodes = visibleNodes.OrderByDescending(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.First().DiscountAmount : x.Price).ThenByDescending(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.Last().DiscountAmount : 0).ToList(); //Highest-Lowest } if (visibleNodes.Count > 0) { _ContentNodes.AddRange(visibleNodes); // DELAYED QUERIES TO EAGER LOAD RELATED DATA FOR PERFORMANCE BOOST List <int> ids = visibleNodes.Select(p => p.Id).ToList(); var futureQuery = NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(ids) .Fetch(p => p.Specials).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(ids) .Fetch(p => p.ProductOptions).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(ids) .Fetch(p => p.ProductKitComponents).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(ids) .Fetch(p => p.ProductTemplates).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(ids) .Fetch(p => p.Reviews).Eager .Future <Product>(); futureQuery.ToList(); } if (_pageSize == 0) { _pageSize = _ContentNodes.Count; } int minimumPageSize = AlwaysConvert.ToInt(PageSizeOptions.Items[0].Value); PageSizePanel.Visible = _searchResultCount > minimumPageSize; //BIND PAGE BindPage(); } int manufecturerCount = ManufacturerDataSource.CountAll(); foreach (ListItem li in SortResults.Items) { if (li.Value.StartsWith("Manufacturer")) { li.Enabled = manufecturerCount > 0; } } }
protected void Page_Load(object sender, System.EventArgs e) { Page.Title = string.IsNullOrEmpty(_category.Title) ? _category.Name : _category.Title; Caption.Text = _category.Name; if (!Page.IsPostBack) { //initialize search sorting and paging criteria based on query string parameters HiddenPageIndex.Value = AlwaysConvert.ToInt(Request.QueryString["p"]).ToString(); string tempSort = Request.QueryString["s"]; if (!string.IsNullOrEmpty(tempSort)) { ListItem item = SortResults.Items.OfType <ListItem>().SingleOrDefault(x => string.Compare(x.Value, tempSort, StringComparison.InvariantCultureIgnoreCase) == 0); if (item != null) { item.Selected = true; } } } //initialize paging vars _hiddenPageIndex = AlwaysConvert.ToInt(HiddenPageIndex.Value); _productCount = ProductDataSource.CountForCategory(_categoryId, false, true); _lastPageIndex = ((int)Math.Ceiling(((double)_productCount / (double)_pageSize))) - 1; if (_hiddenPageIndex > _lastPageIndex) { _hiddenPageIndex = _lastPageIndex; } if (_pageSize == 0) { _pageSize = _productCount; } //bind products ProductList.DataSource = ProductDataSource.LoadForCategory(true, _categoryId, false, true, SortResults.SelectedValue, _pageSize, (_hiddenPageIndex * _pageSize)); ProductList.DataBind(); ProductsPanel.Visible = _productCount > 0; if (_productCount == 0 && CategoryDataSource.CountForParent(_categoryId, true) == 0) { NoResultPanel.Visible = true; } //bind paging int totalPages; if (_pageSize <= 0) { totalPages = 1; } else { totalPages = (int)Math.Ceiling((double)_productCount / _pageSize); } if (_lastPageIndex > 0) { PagerPanel.Visible = true; PagerPanelTop.Visible = true; List <PagerLinkData> pagerLinkData = GetPagingLinkData(totalPages); PagerControls.DataSource = pagerLinkData; PagerControls.DataBind(); PagerControlsTop.DataSource = pagerLinkData; PagerControlsTop.DataBind(); PagerMessageTop.Text = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages); PagerMessageBottom.Text = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages); } else { PagerPanel.Visible = false; PagerPanelTop.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { CategoryBreadCrumbs1.Visible = DisplayBreadCrumbs; CategoryBreadCrumbs1.CategoryId = this.CategoryId; //BIND THE DISPLAY ELEMENTS if (IsValidCategory()) { if (_Category != null) { Caption.Text = _Category.Name; if (!string.IsNullOrEmpty(_Category.Summary) && ShowSummary) { CategorySummaryPanel.Visible = true; CategorySummary.Text = _Category.Summary; } else { CategorySummaryPanel.Visible = false; } if (!string.IsNullOrEmpty(_Category.Description) && ShowDescription) { CategoryDescriptionPanel.Visible = true; CategoryDescription.Text = _Category.Description; } else { CategoryDescriptionPanel.Visible = false; } } else { // IF IT IS ROOT CATEGORY Caption.Text = DefaultCaption; } BindSubCategories(); if (_Category != null) { //UPDATE THE RESULT INDEX MESSAGE _totalProducts = ProductDataSource.CountForCategory(true, _Category.Id, false, true); } //INITIALIZE PAGING VARIABLES InitializePagingVars(false); int startRowIndex = (_PageSize * _HiddenPageIndex); int endRowIndex = startRowIndex + _PageSize; if (endRowIndex > _totalProducts) { endRowIndex = _totalProducts; } if (_totalProducts == 0) { startRowIndex = -1; } ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, _totalProducts); if (_Category != null) { var products = ProductDataSource.LoadForCategory(true, _Category.Id, false, true, SortResults.SelectedValue, PageSize, startRowIndex); if (products.Count > 0) { var productIds = products.Select(p => p.Id) .ToList <int>(); var futureQuery = NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.Manufacturer).Eager .Fetch(p => p.Specials).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.ProductOptions).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.ProductKitComponents).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.ProductTemplates).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.Reviews).Eager .Future <Product>(); futureQuery.ToList(); } CatalogNodeList.DataSource = products; CatalogNodeList.DataBind(); } if (_totalProducts > 0) { phCategoryContents.Visible = true; //BIND THE PAGING CONTROLS FOOTER BindPagingControls(); } else { ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, 0, 0, 0); //HIDE THE CONTENTS phCategoryContents.Visible = false; phEmptyCategory.Visible = (_Category != null && _Category.CatalogNodes.Count == 0); phNoSearchResults.Visible = !phEmptyCategory.Visible; } //UPDATE AJAX PANEL SearchResultsAjaxPanel.Update(); } else { CategoryHeaderPanel.Visible = false; } int manufecturerCount = ManufacturerDataSource.CountAll(); foreach (ListItem li in SortResults.Items) { if (li.Value.StartsWith("Manufacturer")) { li.Enabled = manufecturerCount > 0; } } }