Solved

Data List Custom Number Paging

Posted on 2007-04-05
1
286 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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