jellybeannn -4 Junior Poster

I'm working on the book "Beginning Aspnet E-Commerce with C#", but I have encountered a problem. The tutorial includes a Pager Control, this works fine for all of the products it is just when the a department is selected the pager does not work, only after a Category is selected that it works.


Pager.ascx.cs

// simple struct that represent a (page number, url) association
public struct PageURL
{
    private string page;
    private string url;
    
        // page and url property definitions
    public string Page
    {
        get
        {
            return page;
        }
    }

    public string URL
    {
        get
        {
            return url;
        }
    }

        // constructor
    public PageURL(string page, string url)
    {
        this.page = page;
        this.url = url;
    }
}

    // the Pager control
public partial class UserControls_Pager : System.Web.UI.UserControl
{
        // show the pager
    public void Show(int currentPage, int howManyPages, string firstPageURL,
        string pageURLFormat, bool showPages)
    {
            // display paging controls
        if (howManyPages > 1)
        {
                // make the pager visible
            this.Visible = true;
                // display the  current page
            currentPageLabel.Text = currentPage.ToString();
            howManyPagesLabel.Text = howManyPages.ToString();
                // create the previous link
            if (currentPage == 1)
            {
                previousLink.Enabled = false;
            }
            else
            {
                previousLink.NavigateUrl = (currentPage == 2) ?
                    firstPageURL : String.Format(pageURLFormat, currentPage - 1);
            }
                // create the next link
            if (currentPage == howManyPages)
            {
                nextLink.Enabled = false;
            }
            else
            {
                nextLink.NavigateUrl = 
                    String.Format(pageURLFormat, currentPage + 1);
            }
                // create the page links
            if (showPages)
            {
                    // the list of pages and their URLS as an array
                PageURL[] pages = new PageURL[howManyPages];
                    // generate (page, url) elements
                pages[0] = new PageURL("1", firstPageURL);
                for (int i = 2; i <= howManyPages; i++)
                {
                    pages[i - 1] =
                        new PageURL(i.ToString(), String.Format(pageURLFormat, i));
                }
                    // do not generate a link for the current page
                pages[currentPage - 1] = new PageURL((currentPage).ToString(), "");
                    // feed the pages to the repeater
                pagesRepeater.DataSource = pages;
                pagesRepeater.DataBind();
            }
        }
    }

ProductList.ascx.cs

public partial class UserControls_ProductsList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PopulateControls();
    }

    private void PopulateControls()
    {
            // retrieve DepartmentId from the queryString
        string departmentId = Request.QueryString["DepartmentID"];
            // retrieve CategoryId from the queryString
        string categoryId = Request.QueryString["CategoryID"];
            // retrieve Page from the queryString
        string page = Request.QueryString["Page"];
        if (page == null) page = "1";
            // retrieve SearchString from QueryString
        string searchString = Request.QueryString["Search"];
            // how many pages of products
        int howManyPages = 1;
            // pager links format
        string firstPageURL = "";
        string pagerFormat = "";

            // if performing a product search
        if (searchString != null)
        {
                // retrieve allWords from QueryString
            string allWords = Request.QueryString["AllWords"];
                // perform search
            list.DataSource = CatalogAccess.Search(searchString, allWords,
                page, out howManyPages);
            list.DataBind();
                // display pager
            firstPageURL = Link.ToSearch(searchString, allWords.ToUpper() ==
                "TRUE", "1");
            pagerFormat = Link.ToSearch(searchString, allWords.ToUpper() ==
                "TRUE", "{0}");
        }
            // if browsing a category...
        else if (categoryId != null)
        {
                // retrievelist of products in a category
            list.DataSource =
                CatalogAccess.GetProductsInCategory(categoryId, page, out howManyPages);
            list.DataBind();
                // get first page url and pager format
            firstPageURL = Link.ToCategory(departmentId, categoryId, "1");
            pagerFormat = Link.ToCategory(departmentId, categoryId, "{0}");
        }
        else if (departmentId != null)
        {
            // retrieve list of products on department promotion
            list.DataSource =
                CatalogAccess.GetProductsOnDeptPromo(departmentId, page, out howManyPages);
            list.DataBind();
            // get first page url and pager format
            firstPageURL = Link.ToDepartment(departmentId, "1");
            pagerFormat = Link.ToDepartment(departmentId, "{0}");
        }
        else
        {
            // retrieve list of products on catalog promotion
            list.DataSource =
                CatalogAccess.GetProductsOnCatPromo(page, out howManyPages);
            list.DataBind();
            // have the current page as an integer
            int currentPage = Int32.Parse(page);
        }
                // display pager controls
            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)
    {
            // execute when each item of the list is bound to the data source
        DataRowView dataRow = (DataRowView)e.Item.DataItem;
        string productId = dataRow["ProductID"].ToString();
        DataTable attrTable = CatalogAccess.GetProductAttributes(productId);

            // get the attribute placeHolder
        PlaceHolder attrPlaceHolder =
            (PlaceHolder)e.Item.FindControl("attrPlaceHolder");

            // temp variables
        string prevAttributeName = "";
        string attributeName = "";
        string attributeValue = "";
        string attributeValueId = "";

            // current dropdown for attribute values
        Label attributeNameLabel;
        DropDownList attributeValuesDropDown = new DropDownList();

            // read the list of attributes
        foreach (DataRow r in attrTable.Rows)
        {
                // get attribute data
            attributeName = r["AttributeName"].ToString();
            attributeValue = r["AttributeValue"].ToString();
            attributeValueId = r["AttributeValueID"].ToString();

                // if starting a new attribute
            if (attributeName != prevAttributeName)
            {
                prevAttributeName = attributeName;
                attributeNameLabel = new Label();
                attributeNameLabel.Text = attributeName + ": ";
                attributeValuesDropDown = new DropDownList();
                attrPlaceHolder.Controls.Add(attributeNameLabel);
                attrPlaceHolder.Controls.Add(attributeValuesDropDown);
            }
                // add a new attribute value to the dropdown list
            attributeValuesDropDown.Items.Add(new ListItem(attributeValue, attributeValueId));
        } 
    }
}

Can anyone please assist me with this?