Click here to Skip to main content
15,886,724 members
Articles / Web Development / HTML

SmartPager: a Flickr-style pager control with go-to-page popup layer

Rate me:
Please Sign up or sign in to vote.
4.76/5 (22 votes)
8 Jan 2007CPOL10 min read 167.4K   2.2K   117  
ASP.NET pager control similar to Flickr's paging interface, but with tooltips and go-to-page popup layer allowing you to enter the required page number.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;


namespace Avg.Controls
{
	public class Demo2 : System.Web.UI.Page
	{
		protected SmartPager PgrMain;
		protected DataGrid GrdMain;


		override protected void OnInit(EventArgs e)
		{
			this.Load += new System.EventHandler(this.Page_Load);
			base.OnInit(e);
		}

		
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
				PopulateGrid();
		}


		void PopulateGrid()
		{
			string cs = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", Server.MapPath("data.mdb"));
			string query = "select OrderId, Freight, ShipName from Orders order by ShipName";

			OleDbConnection conn = new OleDbConnection(cs);
			conn.Open();

			DataTable orders = new DataTable();
			OleDbDataAdapter adap = new OleDbDataAdapter(query, conn);
			adap.Fill(orders);

			conn.Close();

			GrdMain.DataSource = orders;
			DataBind();

			PgrMain.PageCount = GrdMain.PageCount;

			ArrayList tooltips = new ArrayList();
			for (int i=0; i<orders.Rows.Count; i += GrdMain.PageSize)
				tooltips.Add(orders.Rows[i]["ShipName"].ToString());
			PgrMain.SetTooltips( (string[])tooltips.ToArray(typeof(string)) );
		}

		
		protected void PgrMain_PageChanged(object sender, System.EventArgs e)
		{
			GrdMain.CurrentPageIndex = PgrMain.CurrentPage - 1;
			PopulateGrid();
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
Ash is a C# developer (MCAD) with a background developing e-commerce and content management solutions. His current role includes working with VOIP systems, integration and maintenance of business and billing apps. His personal projects include the ScrollingGrid web control to enable cross-browser freeze-header 2-way scrolling of DataGrids. His other interests include travel, cinema, Squash, photography, Muay Thai.

Comments and Discussions