Hi, I'm working on the book "Beginning Aspnet e-Commerce in C#". But I have a problem with the pager control, my products pager works, it's just when the website is opened in Default.aspx that the Department specials pager do not work.
Can anyone assist me please?
Pager.ascx.cs
public struct PageURL
{
private string page;
private string url;
public string Page
{
get
{
return page;
}
}
public string URL
{
get
{
return url;
}
}
public PageURL(string page, string url)
{
this.page = page;
this.url = url;
}
}
public partial class UserControls_Pager : System.Web.UI.UserControl
{
public void Show(int currentPage, int howManyPages, string firstPageURL,
string pageURLFormat, bool showPages)
{
if (howManyPages > 1)
{
this.Visible = true;
currentPageLabel.Text = currentPage.ToString();
howManyPagesLabel.Text = howManyPages.ToString();
if (currentPage == 1)
{
previousLink.Enabled = false;
}
else
{
previousLink.NavigateUrl = (currentPage == 2) ?
firstPageURL : String.Format(pageURLFormat, currentPage - 1);
}
if (currentPage == howManyPages)
{
nextLink.Enabled = false;
}
else
{
nextLink.NavigateUrl =
String.Format(pageURLFormat, currentPage + 1);
}
if (showPages)
{
PageURL[] pages = new PageURL[howManyPages];
pages[0] = new PageURL("1", firstPageURL);
for (int i = 2; i <= howManyPages; i++)
{
pages[i - 1] =
new PageURL(i.ToString(), String.Format(pageURLFormat, i));
}
pages[currentPage - 1] = new PageURL((currentPage).ToString(), "");
pagesRepeater.DataSource = pages;
pagesRepeater.DataBind();
}
}
}
ProductsList.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
PopulateControls();
}
private void PopulateControls()
{
string departmentId = Request.QueryString["DepartmentID"];
string categoryId = Request.QueryString["CategoryID"];
string page = Request.QueryString["Page"];
if (page == null) page = "1";
string searchString = Request.QueryString["Search"];
int howManyPages = 1;
string firstPageURL = "";
string pagerFormat = "";
if (searchString != null)
{
string allWords = Request.QueryString["AllWords"];
list.DataSource = CatalogAccess.Search(searchString, allWords,
page, out howManyPages);
list.DataBind();
firstPageURL = Link.ToSearch(searchString, allWords.ToUpper() ==
"TRUE", "1");
pagerFormat = Link.ToSearch(searchString, allWords.ToUpper() ==
"TRUE", "{0}");
}
else if (categoryId != null)
{
list.DataSource =
CatalogAccess.GetProductsInCategory(categoryId, page, out howManyPages);
list.DataBind();
firstPageURL = Link.ToCategory(departmentId, categoryId, "1");
pagerFormat = Link.ToCategory(departmentId, categoryId, "{0}");
}
else if (departmentId != null)
{
list.DataSource =
CatalogAccess.GetProductsOnDeptPromo(departmentId, page, out howManyPages);
list.DataBind();
firstPageURL = Link.ToDepartment(departmentId, "1");
pagerFormat = Link.ToDepartment(departmentId, "{0}");
}
else
{
list.DataSource =
CatalogAccess.GetProductsOnCatPromo(page, out howManyPages);
list.DataBind();
int currentPage = Int32.Parse(page);
}
topPager.Show(int.Parse(page), howManyPages, firstPageURL, pagerFormat, false);
bottomPager.Show(int.Parse(page), howManyPages, firstPageURL, pagerFormat, true);
}
protected void list_ItemDataBound(object sender, DataListItemEventArgs e)
{
DataRowView dataRow = (DataRowView)e.Item.DataItem;
string productId = dataRow["ProductID"].ToString();
DataTable attrTable = CatalogAccess.GetProductAttributes(productId);
PlaceHolder attrPlaceHolder =
(PlaceHolder)e.Item.FindControl("attrPlaceHolder");
string prevAttributeName = "";
string attributeName = "";
string attributeValue = "";
string attributeValueId = "";
Label attributeNameLabel;
DropDownList attributeValuesDropDown = new DropDownList();
foreach (DataRow r in attrTable.Rows)
{
attributeName = r["AttributeName"].ToString();
attributeValue = r["AttributeValue"].ToString();
attributeValueId = r["AttributeValueID"].ToString();
if (attributeName != prevAttributeName)
{
prevAttributeName = attributeName;
attributeNameLabel = new Label();
attributeNameLabel.Text = attributeName + ": ";
attributeValuesDropDown = new DropDownList();
attrPlaceHolder.Controls.Add(attributeNameLabel);
attrPlaceHolder.Controls.Add(attributeValuesDropDown);
}
attributeValuesDropDown.Items.Add(new ListItem(attributeValue, attributeValueId));
}
}