用户自定义控件的应用。
点击次数:11 次 发布日期:2008-11-26 23:43:00 作者:源代码网
|
源代码网推荐asp.net中的 用户自定义控件 特点 1:实现服用;2:方便创建(相对与组件)。 以下为一个分页导航条的sample, 接见于Webdiyer,相信很多人已经如雷贯耳了,我也不多介绍。本问只是简单的 练习之作,没有什么深奥的算法和架构。 源代码网推荐 源代码网推荐----behindCode--------------------------------------------------------------------------------------------------------------- 源代码网推荐 源代码网推荐namespace GallonKit 源代码网推荐{ 源代码网推荐 using System; 源代码网推荐 using System.Data; 源代码网推荐 using System.Drawing; 源代码网推荐 using System.Web; 源代码网推荐 using System.Web.UI.WebControls; 源代码网推荐 using System.Web.UI.HtmlControls; 源代码网推荐 源代码网推荐 /// <summary> 源代码网推荐 /// PageBar 的摘要说明。 源代码网推荐 /// </summary> 源代码网推荐 源代码网推荐 public delegate void PageLocalBtn(uint index); 源代码网推荐 源代码网推荐 public class PageBar : System.Web.UI.UserControl 源代码网推荐 { 源代码网推荐 protected System.Web.UI.WebControls.LinkButton LinkButton1; 源代码网推荐 protected System.Web.UI.WebControls.LinkButton btn_fistPage; 源代码网推荐 protected System.Web.UI.WebControls.LinkButton btn_lastPage; 源代码网推荐 protected System.Web.UI.WebControls.LinkButton btn_prePage; 源代码网推荐 protected System.Web.UI.WebControls.LinkButton btn_nextPage; 源代码网推荐 protected System.Web.UI.WebControls.Label lb_PageCount; 源代码网推荐 protected System.Web.UI.WebControls.TextBox tb_pageIndex; 源代码网推荐 protected System.Web.UI.WebControls.LinkButton btn_local; 源代码网推荐 public PageLocalBtn LocalBtnClick; 源代码网推荐 源代码网推荐 源代码网推荐 private void Page_Load(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 // 在此处放置用户代码以初始化页面 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 private bool IsUint(string strInt) 源代码网推荐 { 源代码网推荐 try 源代码网推荐 { 源代码网推荐 uint.Parse(strInt); 源代码网推荐 } 源代码网推荐 catch(Exception e) 源代码网推荐 { 源代码网推荐 return false; 源代码网推荐 } 源代码网推荐 源代码网推荐 return true; 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 public uint pageIndex 源代码网推荐 { 源代码网推荐 get{ 源代码网推荐 if (this.IsUint(this.tb_pageIndex.Text.Trim())) 源代码网推荐 return uint.Parse(this.tb_pageIndex.Text.Trim()); 源代码网推荐 return 0; 源代码网推荐 } 源代码网推荐 源代码网推荐 set{ 源代码网推荐 if (this.IsUint(value.ToString())) 源代码网推荐 this.tb_pageIndex.Text = value.ToString(); 源代码网推荐 else 源代码网推荐 throw new System.Exception("页数范围不正确!"); 源代码网推荐 源代码网推荐 } 源代码网推荐 } 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 public uint pageCount 源代码网推荐 { 源代码网推荐 get 源代码网推荐 { 源代码网推荐 object obj = ViewState["PageCount__"]; 源代码网推荐 return (obj == null)?0:(uint)obj; 源代码网推荐 } 源代码网推荐 源代码网推荐 set 源代码网推荐 { 源代码网推荐 源代码网推荐 if (this.IsUint(value.ToString())) 源代码网推荐 { 源代码网推荐 this.lb_PageCount.Text = value.ToString(); 源代码网推荐 ViewState["PageCount__"] = value; 源代码网推荐 } 源代码网推荐 else 源代码网推荐 throw new System.Exception("页数范围不正确!"); 源代码网推荐 } 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 源代码网推荐 #region Web 窗体设计器生成的代码 源代码网推荐 override protected void OnInit(EventArgs e) 源代码网推荐 { 源代码网推荐 // 源代码网推荐 // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 源代码网推荐 // 源代码网推荐 InitializeComponent(); 源代码网推荐 base.OnInit(e); 源代码网推荐 } 源代码网推荐 源代码网推荐 /// <summary> 源代码网推荐 /// 设计器支持所需的方法 - 不要使用代码编辑器 源代码网推荐 /// 修改此方法的内容。 源代码网推荐 /// </summary> 源代码网推荐 private void InitializeComponent() 源代码网推荐 { 源代码网推荐 this.btn_fistPage.Click += new System.EventHandler(this.btn_fistPage_Click); 源代码网推荐 this.btn_prePage.Click += new System.EventHandler(this.btn_prePage_Click); 源代码网推荐 this.btn_nextPage.Click += new System.EventHandler(this.btn_nextPage_Click); 源代码网推荐 this.btn_lastPage.Click += new System.EventHandler(this.btn_lastPage_Click); 源代码网推荐 this.btn_local.Click += new System.EventHandler(this.btn_local_Click); 源代码网推荐 this.Load += new System.EventHandler(this.Page_Load); 源代码网推荐 源代码网推荐 } 源代码网推荐 #endregion 源代码网推荐 源代码网推荐 private void EnableAllBtn() 源代码网推荐 { 源代码网推荐 this.btn_fistPage.Enabled = true; 源代码网推荐 this.btn_lastPage.Enabled = true; 源代码网推荐 this.btn_prePage.Enabled = true; 源代码网推荐 this.btn_nextPage.Enabled = true; 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 private void ChangeBtnStatus(char BtnIndex) 源代码网推荐 { 源代码网推荐 switch(BtnIndex) 源代码网推荐 { 源代码网推荐 case "F": 源代码网推荐 this.btn_fistPage.Enabled = false; 源代码网推荐 this.btn_prePage.Enabled = false; 源代码网推荐 break; 源代码网推荐 case "L": 源代码网推荐 this.btn_nextPage.Enabled = false; 源代码网推荐 this.btn_lastPage.Enabled = false; 源代码网推荐 break; 源代码网推荐 case "P": 源代码网推荐 this.btn_prePage.Enabled = false; 源代码网推荐 break; 源代码网推荐 case "N": 源代码网推荐 this.btn_nextPage.Enabled = false; 源代码网推荐 break; 源代码网推荐 } 源代码网推荐 } 源代码网推荐 源代码网推荐 private void btn_lastPage_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 EnableAllBtn(); 源代码网推荐 源代码网推荐 if( LocalBtnClick != null) 源代码网推荐 { 源代码网推荐 LocalBtnClick(this.pageCount); 源代码网推荐 } 源代码网推荐 源代码网推荐 this.ChangeBtnStatus("L"); 源代码网推荐 } 源代码网推荐 源代码网推荐 private void btn_fistPage_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 EnableAllBtn(); 源代码网推荐 if( LocalBtnClick != null) 源代码网推荐 { 源代码网推荐 LocalBtnClick(1); 源代码网推荐 } 源代码网推荐 源代码网推荐 this.ChangeBtnStatus("F"); 源代码网推荐 } 源代码网推荐 源代码网推荐 private void btn_prePage_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 EnableAllBtn(); 源代码网推荐 源代码网推荐 if (LocalBtnClick == null) return; 源代码网推荐 if (this.pageIndex>1) 源代码网推荐 this.pageIndex--; 源代码网推荐 else 源代码网推荐 { 源代码网推荐 this.ChangeBtnStatus("P"); 源代码网推荐 this.ChangeBtnStatus("F"); 源代码网推荐 } 源代码网推荐 源代码网推荐 this.LocalBtnClick(this.pageIndex); 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 private void btn_nextPage_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 EnableAllBtn(); 源代码网推荐 if (LocalBtnClick == null) return; 源代码网推荐 if (this.pageIndex<this.pageCount) 源代码网推荐 this.pageIndex++; 源代码网推荐 else 源代码网推荐 { 源代码网推荐 this.ChangeBtnStatus("N"); 源代码网推荐 this.ChangeBtnStatus("L"); 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 this.LocalBtnClick(this.pageIndex); 源代码网推荐 } 源代码网推荐 源代码网推荐 private void btn_local_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 EnableAllBtn(); 源代码网推荐 if (this.pageIndex <=1) 源代码网推荐 { 源代码网推荐 this.tb_pageIndex.Text = "1"; 源代码网推荐 this.ChangeBtnStatus("F"); 源代码网推荐 } 源代码网推荐 else 源代码网推荐 { 源代码网推荐 if(this.pageIndex >= this.pageCount ) 源代码网推荐 { 源代码网推荐 this.pageIndex = this.pageCount; 源代码网推荐 this.ChangeBtnStatus("L"); 源代码网推荐 } 源代码网推荐 } 源代码网推荐 源代码网推荐 if( LocalBtnClick != null) 源代码网推荐 LocalBtnClick(this.pageIndex); 源代码网推荐 源代码网推荐 } 源代码网推荐 } 源代码网推荐} 源代码网推荐====================aspx文件===================================================== 源代码网推荐 源代码网推荐 源代码网推荐 源代码网推荐 | 首页 | 前页 | 后页 | 末页 |1 Go |总页数 源代码网推荐 源代码网供稿. |
