Solved

Data List Custom Number Paging

Posted on 2007-04-05
1
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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