Solved

Data List Custom Number Paging

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

710 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