Solved

Data List Custom Number Paging

Posted on 2007-04-05
1
280 Views
Last Modified: 2013-11-07
Hi currently i have custom paging enable with my datalist. However my paging, the navigation links are only Previous page and Next page. Is it possible that i change my custom paging to number paging? Could it be done?

This is my current working codes of the datalist:

using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ProductsControls_ProductViewing : System.Web.UI.UserControl
{
    public static string Image1FileNameTumb;
    int productid;
    int currentPage;
    string categoryId;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateControls();
        }      
    }


    private void PopulateControls()
    {
        // Retrieve CategoryID from the query string
        categoryId = Request.QueryString["categoryId"];

        // Retrieve Page from the query string
        if (Request.QueryString["Page"] != null)
        {
            currentPage = Convert.ToInt32(Request.QueryString["Page"]);
        }
        else
        {
            currentPage = 1;
        }

        // If browsing a category...
        if (categoryId != null)
        {
            // Retrieve list of products in a category
            PagedDataSource objPds = new PagedDataSource();
            DataView dv = new DataView(CatalogAccess.GetProductsInCategory(categoryId));
            objPds.DataSource = dv;
            objPds.AllowPaging = true;
            objPds.PageSize = 9;

            objPds.CurrentPageIndex = currentPage - 1;
            lblCurrentPage.Text = "Page: " + currentPage.ToString();
            if (!objPds.IsFirstPage)
            {
                prevLink.NavigateUrl = Request.CurrentExecutionFilePath + "?categoryId=" + categoryId + "&Page=" + Convert.ToString(currentPage - 1);
            }
            if (!objPds.IsLastPage)
            {
                nextLink.NavigateUrl = Request.CurrentExecutionFilePath + "?categoryId=" + categoryId + "&Page=" + Convert.ToString(currentPage + 1);
            }

            dlProducts.DataSource = objPds;
            dlProducts.DataBind();
        }
    }

    protected void dlProducts_ItemCommand(object Sender, DataListCommandEventArgs e)
    {
        string cmd = ((ImageButton)e.CommandSource).CommandName;
        if (cmd == "Details")
        {
            Label ProductId = ((Label)(e.Item.FindControl("lblProductId")));
            productid = Convert.ToInt32(ProductId.Text);
            categoryId = Request.QueryString["categoryId"];
            currentPage = Convert.ToInt32(Request.QueryString["Page"]);
            Response.Redirect("ProductListing.aspx?productid=" + productid + "&categoryId=" + categoryId);
        }
    }
   

   
}
0
Comment
Question by:banana_split
1 Comment
 
LVL 5

Accepted Solution

by:
Yttribium earned 500 total points
ID: 18857024
You can use the PageCount property of your PagedDataSource, and generate hyperlinks for each page, where you would then page to the correct page using:

objPds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["Page"]);

e.g.

for (int i = 1; i <= objPds.PageCount ; i++)
{
  Build your anchor Links using something like "http://...../...?Page=" + i.ToString()
}




0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now