Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Data » Downloads
 
Add your own
alternative version

Generic Paging for Recordset with Next Back Navigation

, 20 Jun 2005 CPOL
This article is basically about a Paging control required for project purposes. One can use this just by changing three parameters.
Paging_src.zip
Paging
bin
Paging.dll
Global.asax
Paging.csproj.webinfo
style
_vti_cnf
_vti_pvt
access.cnf
deptodoc.btr
doctodep.btr
service.cnf
service.lck
services.cnf
_vti_script
_vti_txt
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Paging
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		#region Private & Protected Variables
		protected System.Web.UI.WebControls.Table tbPickList;
		protected System.Web.UI.WebControls.Table Table1;
		protected System.Web.UI.WebControls.Table tblPaging;
		protected TableRow tr;
		//------------------------------------------------------
		private const int iShowNoPage=7;//-Change Parameter
		private static int jIter=7;//------Change Parameter
		private  int iTotalRec;//Change Paramater
		private static int iFirstStepMod;
		private static int iLastStep;
		private static int zIter=1;
		private  static int iCntMovePtr=1;
		private int iTotalPages;
		//-------------------------------------------------------
		protected System.Web.UI.WebControls.Button btnPrev;
		protected System.Web.UI.WebControls.Button btnNext;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.DropDownList ddlTotalRec;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Button Button1;
		#endregion
		
		#region On Page Load
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			//	if(!IsPostBack)
			//Button1.Attributes.Add("onclick","return alert(addDays(new Date(),10));");
			//LoadDynamicTable();
			//LoadStyleTable();
			// Button1.Attributes.Add("onclick","return alert(addDays(new Date('5/23/2006'),10));");	
			//------------------------------------------------------------------------------------	
			if(iCntMovePtr==1)
			{
				btnPrev.Visible=false;
			}
			CalculatePaging();
			
			//------------------------------------------------------------------------
}
		#endregion

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnPrev.Click += new System.EventHandler(this.btnPrev_Click);
			this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
			this.ddlTotalRec.SelectedIndexChanged += new System.EventHandler(this.ddlTotalRec_SelectedIndexChanged);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region LoadDynamicTable()
		public void LoadDynamicTable()
		{
			TextBox _txt;
			CheckBox _chk;
			LinkButton _lnkBtn;
			tr=new TableRow();
			TableHeader("Id");
			TableHeader("Name");
			TableHeader("Links");
			TableHeader("SelectOption");
			
			for(int i=0;i<5;i++)
			{
				 tr=new TableRow();
				for(int j=0;j<4;j++)
				{
					TableCell tc=new TableCell();
					tc.BorderWidth=1;
					switch(j)
					{
						case 0:
							_txt=new TextBox();
							_txt.Text=j.ToString();
							tc.Controls.Add(_txt);
							break;
						case 1:
							_txt=new TextBox();
							_txt.Text=j.ToString();
							tc.Controls.Add(_txt);
							break;
						case 2:
							_lnkBtn=new LinkButton();
							_lnkBtn.Text="Link"+j;
							tc.Controls.Add(_lnkBtn);
							_lnkBtn.Click += new EventHandler(LinkClick);
							break;
						case 3:
							_chk=new CheckBox();
							_chk.Text="Select";
							tc.Controls.Add(_chk);
							break;
							
					}
					
				tr.Cells.Add(tc);
			
				}
				tbPickList.Rows.Add(tr);
			}
}
		#endregion

		#region LinkClick(Object sender, EventArgs e)
		public void LinkClick(Object sender, EventArgs e)
		{
		
		}
		#endregion

		#region TableHeader
		public void TableHeader(string strHeaderName)
		{
		
			TableHeaderCell tc=new TableHeaderCell();
			
			Literal li=new Literal();
			li.Text=strHeaderName;
			tc.Controls.Add(li);
			tc.BorderWidth=1;
			tr.Cells.Add(tc);
			tbPickList.Rows.Add(tr);
		
		}
		#endregion

		#region LoadStyleTable()
		public void LoadStyleTable()
		{
			string[] tmp = new string[10];
			string StrDump="San~SD~TYY~JKL~LJLJ~LJLJ~LLJ~LKKL~FG~RE";
			tr=new TableRow();
			TblHeader("30","Maturity Date");
			
			TblHeader("31","Maturity Date");
			
			TblHeader("31","Maturity Date");
			
			TblHeader("31","Maturity Date");
		
			TblHeader("31","Maturity Date");
			
			TblHeader("11","Maturity Date");
			
			TblHeader("11","Maturity Date");
			
			TblHeader("11","Maturity Date");
		
			TblHeader("11","Maturity Date");
			
			TblHeader("11","Maturity Date");
			Table1.Rows.Add(tr);
			

			if (StrDump!= "") 
			{
				tr = new TableRow();
				Label _lbl;
				TableCell tc;
				tmp = StrDump.Split("~".ToCharArray());
				Response.Write(tmp.Length);
				for(int i = 0; i<10;i++)
				{
					tc = new TableCell();
					_lbl=new Label();
					_lbl.Text=tmp[i];
					tc.Controls.Add(_lbl);
					tr.Cells.Add(tc);
			
				}
				Table1.Rows.Add(tr);
				}
		
		}
		#endregion

		#region TblHeader
		public void  TblHeader(string width,string HeaderName)
		{
			TableCell tc;
			tc=new TableCell();
			tc.Text=HeaderName;
			//tc.Width.Value;
			tc.Width = new Unit("5px");

			tc.CssClass="darkgray";
			tr.Cells.Add(tc);
			
		}	
		#endregion

		#region Paging
		public void ShowPaging()
		{
			tblPaging.Rows.Clear();
			
			TableRow tr=new TableRow();
			TableCell tc;
			LinkButton _li;
			if((iLastStep==iCntMovePtr && iFirstStepMod != 0) ||(iCntMovePtr == 1 && iTotalPages < iShowNoPage))
			{
				for(int iIter=zIter;iIter<=jIter-(iShowNoPage-iFirstStepMod);iIter++)
				{
					tc=new TableCell();
					_li=new LinkButton();
					_li.ID=Convert.ToString(iIter);
					_li.Text=Convert.ToString(iIter);
					_li.Click+=new EventHandler(LinkToRecord);
					tc.Controls.Add(_li);
					tr.Cells.Add(tc);
				}
				
			}
			else
			{
				for(int iIter=zIter;iIter<=jIter;iIter++)
				{
					tc=new TableCell();
					_li=new LinkButton();
					_li.ID=Convert.ToString(iIter);
					_li.Text=Convert.ToString(iIter);
					
					_li.Click+=new EventHandler(LinkToRecord);
					
					tc.Controls.Add(_li);
					tr.Cells.Add(tc);
			
				}
			}
			tblPaging.Rows.Add(tr);
	

		}
		#endregion

		#region On Page Link Button Click
		public void LinkToRecord(object sender,EventArgs e)
		{

			string strPageNo=((LinkButton)sender).ID;
			//Response.Write("LinkButton Clicked  "+strPageNo);
			Label1.Text="LinkButton Clicked  "+strPageNo;
			tblPaging.Rows.Clear();
			ShowPaging();
		}
		#endregion

		#region Next Navigation
		public void btnNext_Click(object sender, System.EventArgs e)
		{
			tblPaging.Rows.Clear();
			
			if(iLastStep>iCntMovePtr ||  iCntMovePtr>1)
			{
				btnPrev.Visible=true;
				iCntMovePtr++;
				zIter=zIter+iShowNoPage;
				jIter=iShowNoPage+jIter;
				ShowPaging();
		
				Label1.Text="LinkButton Clicked"+zIter;
				if(iCntMovePtr==iLastStep)
				{
					
					btnNext.Visible=false;
				
				}
			
			}


		
		}
		#endregion

		#region Previous Navigation Rec
		public void btnPrev_Click(object sender, System.EventArgs e)
		{
		
			tblPaging.Rows.Clear();
			if(iCntMovePtr>1)
			{
				btnNext.Visible=true;
				iCntMovePtr--;
			
				zIter=zIter - iShowNoPage;
				jIter=jIter - iShowNoPage;
	
				ShowPaging();

				Label1.Text="LinkButton Clicked"+zIter;
			
				if(iCntMovePtr==1)
				{
					btnPrev.Visible=false;
				}
			
			}
		

		
		}
		#endregion

		#region DropDown event
		public void ddlTotalRec_SelectedIndexChanged(object sender, System.EventArgs e)
		{	
			btnNext.Visible=true;
			jIter=7;
			zIter=1;
			iCntMovePtr=1;
			btnPrev.Visible=false;
			CalculatePaging();

		
		}
		#endregion

		#region CalculatePaging Interval
		public void CalculatePaging()
		{
			

			iTotalRec=Convert.ToInt16(ddlTotalRec.SelectedValue);
			if(iTotalRec % 10 !=0)
			{
				iTotalPages=iTotalRec/10+1;
			}
			else
			{
				iTotalPages=iTotalRec/10;
			}
			iFirstStepMod=iTotalPages%iShowNoPage;
			//	Response.Write("iFirstStepMod"+iFirstStepMod);
			if(iFirstStepMod!=0)
			{
				iLastStep=iTotalPages/iShowNoPage+1;
					
			}
			else
			{
				iLastStep=iTotalPages/iShowNoPage;
			}
			if(iTotalRec/10==0 || iTotalPages/iShowNoPage==0)
			{
				btnNext.Visible=false;
				
			}
			if(iTotalRec!=0)
			{
				ShowPaging();
				Label1.Text="LinkButton Clicked  1";
			}
			else
			{
				Label1.Text="Sorry Records found .";
			}
		}

		#endregion
	}
}

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)

Share

About the Author

santosh poojari
Technical Lead
India India
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411028.1 | Last Updated 21 Jun 2005
Article Copyright 2005 by santosh poojari
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid