Solved

Data List Custom Number Paging

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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