www.pudn.com > WebPager.rar > PreNextListJumpPager.cs, change:2005-01-24,size:4565b


using System; 
using System.IO; 
using System.Drawing; 
using System.Drawing.Imaging; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Hooyee.Utils; 
 
namespace Hooyee.WebControls { 
	/// <summary> 
	/// 前页后页以及列表跳转翻页控件。 
	/// </summary> 
	/// <version> 
	/// 20040827	Kriss 
	/// 20050119	Kriss	Instance It 
	/// </version> 
	[System.ComponentModel.ToolboxItem(false)] 
	public class PreNextListJumpPager : DataPagerBase , INamingContainer { 
		#region 构造函数 
		/// <summary> 
		/// 初始化 PreNextListJumpPager 类的新实例。 
		/// </summary> 
		public PreNextListJumpPager() { 
			this.ID = "DataPager"; 
		} 
		#endregion 
 
		#region Image Space 
		private const string BUTTON_PREFIX_IMAGE = "pagerButtonPre.gif"; 
 
		private Literal GetSpaceImage() { 
			Literal imgSpace = new Literal(); 
			string buttonImage = BaseDir + BUTTON_PREFIX_IMAGE ; 
			try{ 
				// buttonImage = WebKit.GetRelPath( buttonImage ); 
				string realFile = HttpContext.Current.Server.MapPath( buttonImage); 
				if (!File.Exists(realFile)){ 
					Bitmap img = (Bitmap) ResManager.GetImage("Images.ButtonPre.gif"); 
					if ( null != img) { 
						img.Save( realFile, ImageFormat.Gif ); 
					} 
				} 
			}catch{ 
			} 
			imgSpace.Text = string.Format( " <img src='{0}'> " , buttonImage ); 
			return imgSpace; 
		} 
		#endregion 
 
		#region Render 
		/// <summary> 
		/// 呈现控件内容。 
		/// </summary> 
		/// <param name="control">包含翻页控件的控件对象。</param> 
		public override void Render( Control control ) { 
			int curPageIndex = PagerInfo.PageIndex; 
			control.Controls.Clear(); 
 
			// 首页 
			control.Controls.Add( GetSpaceImage() ); 
			if ( curPageIndex <= 0 ) { 
				Literal lFirst = new Literal(); 
				lFirst.Text = "<font color='#9A9A9A'>首页</font>"; 
				control.Controls.Add( lFirst ); 
			} else { 
				Control cFirst = CreateGotoPageLink( "首页" , PagerInfo.FirstIndex, "FirstIndex" ); 
				control.Controls.Add( cFirst ); 
			} 
 
			// 上一页 
			control.Controls.Add( GetSpaceImage() ); 
			if ( curPageIndex <= 0 ) { 
				Literal lPrev = new Literal(); 
				lPrev.Text = "<font color='#9A9A9A'>上一页</font>"; 
				control.Controls.Add( lPrev ); 
			} else { 
				Control cPrev = CreateGotoPageLink( "上一页" , PagerInfo.PreIndex, "PreIndex" ); 
				control.Controls.Add( cPrev ); 
			} 
 
			// 下一页 
			control.Controls.Add( GetSpaceImage() ); 
			if ( curPageIndex >= PagerInfo.LastIndex ) { 
				Literal lNext = new Literal(); 
				lNext.Text = "<font color='#9A9A9A'>下一页</font>"; 
				control.Controls.Add( lNext ); 
			} else { 
				Control cNext = CreateGotoPageLink( "下一页" , PagerInfo.NextIndex, "NextIndex" ); 
				control.Controls.Add( cNext ); 
			} 
 
			// 尾页 
			control.Controls.Add( GetSpaceImage() ); 
			if ( curPageIndex >= PagerInfo.LastIndex ) { 
				Literal lLast = new Literal(); 
				lLast.Text = "<font color='#9A9A9A'>尾页</font>"; 
				control.Controls.Add( lLast ); 
			} else { 
				Control cLast = CreateGotoPageLink( "尾页" , PagerInfo.LastIndex, "LastIndex" ); 
				control.Controls.Add( cLast ); 
			} 
 
			// 页次 
			control.Controls.Add( GetSpace(2) ); 
			Literal lPage = new Literal(); 
			lPage.Text = string.Format( "<font color='#9A9A9A'>页次:<B>{0}</B>/<B>{1}</B>页</font>" 
				, curPageIndex + 1 , PagerInfo.PageCount ); 
			control.Controls.Add( lPage ); 
 
			// 篇数 
			control.Controls.Add( GetSpace(2) ); 
			Literal lItem = new Literal(); 
			lItem.Text = string.Format( "<font color='#9A9A9A'>共<B>{0}</B>篇  每页<B>{1}</B>篇</font>" , 
				PagerInfo.ItemCount , PagerInfo.PageSize ); 
			control.Controls.Add( lItem ); 
 
			control.Controls.Add( GetSpace(2) ); 
			DropDownList ddlPages = new DropDownList(); 
			ddlPages.ID = "JumpList"; 
			for ( int i = 1 ; i <= PagerInfo.PageCount ; i++ ) { 
				ddlPages.Items.Add( string.Format( "第{0}页" , i ) ); 
			} 
			ddlPages.SelectedIndex = curPageIndex; 
			if ( PageApplyType == PageApplyType.ByUrl ) { 
				string urlTemplate = PagerInfo.WebSupport.GetPagingUrl( 0 ); 
				urlTemplate = urlTemplate.Substring( 0 , urlTemplate.Length - 1 ); 
				ddlPages.Attributes.Add( "OnClick" , string.Concat( "JavaScript:if(this.selectedIndex!=" 
					, curPageIndex , "){location='" , urlTemplate , "' + this.selectedIndex ;}" ) ); 
			} else if ( PageApplyType == PageApplyType.PostBack ) { 
				ddlPages.AutoPostBack = true; 
				ddlPages.SelectedIndexChanged += new EventHandler(OnPageLinkClick); 
			} 
			control.Controls.Add( ddlPages ); 
		} 
		#endregion 
	} 
}