当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  带搜索的分页控件之一

 带搜索的分页控件之一

点击次数:13 次 发布日期:2008-11-26 10:59:07 作者:源代码网
源代码网推荐      /********************************************************************
源代码网推荐   * FileName : pagefoot.cs
源代码网推荐   * Target : 翻页连接控件,可提供对搜索的支持
源代码网推荐   * Author : Baihao
源代码网推荐   * CreateDate : 2003/03/04 15:50
源代码网推荐   * LastModify : 2003/03/04 15:50
源代码网推荐   * History :
源代码网推荐   2003/03/04 15:50 创建
源代码网推荐  *********************************************************************/
源代码网推荐  
源代码网推荐  using System;
源代码网推荐  using System.Data;
源代码网推荐  using System.Data.SqlClient;
源代码网推荐  using System.Web;
源代码网推荐  using System.Web.UI;
源代码网推荐  using System.Web.UI.WebControls;
源代码网推荐  using System.Web.UI.HtmlControls;
源代码网推荐  using System.ComponentModel;
源代码网推荐  using System.Collections;
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  namespace EII.Lib.WebControls
源代码网推荐  {
源代码网推荐   ///
源代码网推荐   /// 搜索事件处理
源代码网推荐   ///
源代码网推荐   public delegate void SearchHandle(string sInput,int nIndex);
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 翻页连接控件,可提供对搜索的支持
源代码网推荐   ///
源代码网推荐   [Designer("EII.Lib.WebControls.Design.PageFootDesign"), DefaultProperty("CurrentPage"), ToolboxData("<{0}:PageFoot runat=server>"), System.ComponentModel.ToolboxItem(true)]
源代码网推荐   public class PageFoot : System.Web.UI.UserControl
源代码网推荐   {
源代码网推荐  
源代码网推荐   #region Const Define
源代码网推荐  
源代码网推荐   private const string GOTO = "PF_txtGoto";
源代码网推荐   private const string DROP = "PF_dplSearch";
源代码网推荐   private const string END = "";
源代码网推荐   private const string HIDDEN = "PF_Hidden";
源代码网推荐  
源代码网推荐   #endregion
源代码网推荐  
源代码网推荐   #region Member variable
源代码网推荐  
源代码网推荐  
源代码网推荐   private string current = "";
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 在点击了搜索后,激发的事件,使用时要处理
源代码网推荐   ///
源代码网推荐   public event SearchHandle SearchEvent ;
源代码网推荐  
源代码网推荐  
源代码网推荐   protected string m_sIndex = "?PageIndex=";
源代码网推荐   ///
源代码网推荐   /// 当前页数
源代码网推荐   ///
源代码网推荐   protected int nPage = 1;
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 每页条数
源代码网推荐   ///
源代码网推荐   protected int nPageSize = 10;
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 总记录数
源代码网推荐   ///
源代码网推荐   protected int nRowCount = 1;
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 总页数
源代码网推荐   ///
源代码网推荐   private int nPageCount = 1;
源代码网推荐  
源代码网推荐   // ///
源代码网推荐   // /// 总页数, 只读
源代码网推荐   // ///
源代码网推荐   // public int PageCount
源代码网推荐   // {
源代码网推荐   // get{return this.nPageCount ;}
源代码网推荐   // }
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 第一页的连接
源代码网推荐   ///
源代码网推荐   protected string FirstHead = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 前一页的连接
源代码网推荐   ///
源代码网推荐   protected string PreHead = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 下一页的连接
源代码网推荐   ///
源代码网推荐   protected string NextHead = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 最后一页的连接
源代码网推荐   ///
源代码网推荐   protected string LastHead = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 关闭第一页的连接
源代码网推荐   ///
源代码网推荐   protected string FirstFoot = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 关闭前一页的连接
源代码网推荐   ///
源代码网推荐   protected string PreFoot = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 关闭后一页的连接
源代码网推荐   ///
源代码网推荐   protected string NextFoot = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 关闭最后一页的连接
源代码网推荐   ///
源代码网推荐   protected string LastFoot = "";
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 是否显示搜索栏
源代码网推荐   ///
源代码网推荐   public bool ShowSearch = false;
源代码网推荐  
源代码网推荐   // public string ControlName = "";
源代码网推荐  
源代码网推荐   private ArrayList al;
源代码网推荐  
源代码网推荐   private ImageButton btnFoot_Search;
源代码网推荐   private ImageButton btnFoot_GO;
源代码网推荐   private System.Web.UI.WebControls.Label Label1;
源代码网推荐   private TextBox stxt;
源代码网推荐   private System.Web.UI.WebControls.TextBox txtFoot_Goto;
源代码网推荐   private System.Web.UI.WebControls.DropDownList SearchTarget;
源代码网推荐  
源代码网推荐   private bool bInit = false;
源代码网推荐  
源代码网推荐   #endregion
源代码网推荐  
源代码网推荐  
源代码网推荐   #region Property
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 页面的参数,用于在分页时读取页数(eg:PageIndex=14)
源代码网推荐   ///
源代码网推荐   public string PageIndex
源代码网推荐   {
源代码网推荐   set
源代码网推荐   {
源代码网推荐  
源代码网推荐   m_sIndex = "?"+value+"=";
源代码网推荐   if(current.IndexOf("?") >= 0)
源代码网推荐   m_sIndex = m_sIndex.Replace("?","&");
源代码网推荐   }
源代码网推荐   get{return (m_sIndex.Length>0)?m_sIndex.Substring(1,m_sIndex.Length-2):"";}
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   // public event EventHandler Click;
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 当前页面的名称,用于在分页时形成指向另一个页面的连接(eg:List.aspx)
源代码网推荐   ///
源代码网推荐   public string CurrentPage
源代码网推荐   {
源代码网推荐   get
源代码网推荐   {
源代码网推荐   return current;
源代码网推荐   }
源代码网推荐  
源代码网推荐   set
源代码网推荐   {
源代码网推荐   current = value;
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐   #endregion
源代码网推荐  
源代码网推荐   #region Public Method
源代码网推荐   ///
源代码网推荐   /// 改变搜索控件中的选择项目:用字符串数组
源代码网推荐   ///
源代码网推荐   ///
源代码网推荐   public void ChangeSelectItem(string[] ss)
源代码网推荐   {
源代码网推荐   al = new ArrayList();
源代码网推荐   foreach(string s in ss)
源代码网推荐   {
源代码网推荐   al.Add(s);
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 改变搜索控件中的选择项目:用ArrayList
源代码网推荐   ///
源代码网推荐   ///
源代码网推荐   public void ChangeSelectItem(ArrayList ss)
源代码网推荐   {
源代码网推荐   al =ss;
源代码网推荐   }
源代码网推荐  
源代码网推荐   #endregion
源代码网推荐  
源代码网推荐  
源代码网推荐   #region Private Method
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 改变连接目标
源代码网推荐   ///
源代码网推荐   private void ChangeLink()
源代码网推荐   {
源代码网推荐   char cLink = "?";
源代码网推荐   if(current.IndexOf(cLink) >= 0 )
源代码网推荐   {
源代码网推荐   m_sIndex = m_sIndex.Replace(cLink,"&");
源代码网推荐   cLink = "&";
源代码网推荐   }
源代码网推荐   int i;
源代码网推荐   if( (i = current.IndexOf(m_sIndex.Substring(1))) >= 0)
源代码网推荐   {
源代码网推荐   char ch = current[i - 1];
源代码网推荐   int k = current.IndexOf(cLink,i);
源代码网推荐   if( k >= 0)
源代码网推荐   current = current.Remove(i-1 ,k + 1 -i);
源代码网推荐   else
源代码网推荐   current = current.Remove(i - 1 ,current.Length + 1 - i );
源代码网推荐  
源代码网推荐   m_sIndex = m_sIndex.Replace (cLink,ch);
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 添加搜索控件
源代码网推荐   ///
源代码网推荐   private void AddSearch()
源代码网推荐   {
源代码网推荐  
源代码网推荐   this.btnFoot_Search = new ImageButton ();
源代码网推荐   this.Label1 = new Label();
源代码网推荐   this.stxt = new TextBox();
源代码网推荐   this.SearchTarget = new DropDownList();
源代码网推荐  
源代码网推荐  
源代码网推荐   // this.lcnSecond = new Label();
源代码网推荐   // this.lcnFirst = new Label();
源代码网推荐  
源代码网推荐  
源代码网推荐   //搜索标签
源代码网推荐   Label1.Text = "搜索";
源代码网推荐   this.Controls.Add(Label1);
源代码网推荐  
源代码网推荐   //搜索目标输入
源代码网推荐   stxt.MaxLength = 40;
源代码网推荐   stxt.Columns = 12;
源代码网推荐   this.Controls.Add(stxt);
源代码网推荐  
源代码网推荐   //搜索条件
源代码网推荐   SearchTarget.ID = DROP;
源代码网推荐   DataTable dt = new DataTable();
源代码网推荐   DataRow dr;
源代码网推荐  
源代码网推荐   dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
源代码网推荐   dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
源代码网推荐   int i = 0;
源代码网推荐   foreach(object o in al)
源代码网推荐   {
源代码网推荐   dr = dt.NewRow();
源代码网推荐   dr[0] = i++;
源代码网推荐   dr[1] = (string)o;
源代码网推荐  
源代码网推荐   dt.Rows.Add(dr);
源代码网推荐   }
源代码网推荐  
源代码网推荐   DataView dv = new DataView(dt);
源代码网推荐  
源代码网推荐   SearchTarget.DataSource = dv;
源代码网推荐   SearchTarget.DataTextField = "StringValue";
源代码网推荐   SearchTarget.DataValueField = "IntegerValue";
源代码网推荐   SearchTarget.DataBind();
源代码网推荐   this.Controls.Add(SearchTarget);
源代码网推荐  
源代码网推荐   //搜索事件处理
源代码网推荐   btnFoot_Search.Click += new ImageClickEventHandler(Search_Click);
源代码网推荐   btnFoot_Search.ImageUrl = @"/Images/search_button.gif";
源代码网推荐   this.Controls.Add(btnFoot_Search);
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 初始化控件
源代码网推荐   ///
源代码网推荐   private void CustomInit()
源代码网推荐   {
源代码网推荐  
源代码网推荐   if((current!="")&&(m_sIndex!= "")&&(nPageCount!= 0))
源代码网推荐   {
源代码网推荐  
源代码网推荐   ChangeLink();
源代码网推荐   if(nPage != 1)
源代码网推荐   {
源代码网推荐   FirstHead = "";
源代码网推荐   FirstFoot = END;
源代码网推荐   }
源代码网推荐   if(nPage > 1)
源代码网推荐   {
源代码网推荐   PreHead = "";
源代码网推荐   PreFoot = END;
源代码网推荐   }
源代码网推荐  
源代码网推荐   if(nPage < nPageCount)
源代码网推荐   {
源代码网推荐   NextHead = "";
源代码网推荐   NextFoot = END;
源代码网推荐   }
源代码网推荐  
源代码网推荐   if(nPage != nPageCount)
源代码网推荐   {
源代码网推荐   LastHead = "";
源代码网推荐   LastFoot = END;
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐   // create Controls
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐   #endregion
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 通过当前数据源显示分页控件
源代码网推荐   ///
源代码网推荐   /// 当前页序
源代码网推荐   /// 每页大小
源代码网推荐   /// 数据源记录总数
源代码网推荐   ///
源代码网推荐   public int Show(int page,int pagesize,int rowCount)
源代码网推荐   {
源代码网推荐   // nPage = page;
源代码网推荐   // nPageCount = countpage;
源代码网推荐   // 在此处放置用户代码以初始化页面
源代码网推荐   //Response.Write(FirstHead);
源代码网推荐  
源代码网推荐  
源代码网推荐   if(page <1)
源代码网推荐   page = 1;
源代码网推荐   nPage = page;
源代码网推荐   nPageSize = pagesize;
源代码网推荐   nRowCount = rowCount;
源代码网推荐  
源代码网推荐   nPageCount = (nRowCount/nPageSize )+(((nRowCount%nPageSize ) == 0)?0:1);
源代码网推荐  
源代码网推荐   if(nPageCount < 1)
源代码网推荐   nPageCount = 1;
源代码网推荐  
源代码网推荐   if(nPage > nPageCount)
源代码网推荐   nPage = nPageCount;
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   DataBind();
源代码网推荐   // this.HasChildViewState = true;
源代码网推荐   return nPage;
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 重载初始化
源代码网推荐   ///
源代码网推荐   ///
源代码网推荐   protected override void OnInit(EventArgs e)
源代码网推荐   {
源代码网推荐   //this.EnableViewState = true;
源代码网推荐   current = System.IO.Path.GetFileName(Request.Url.LocalPath)+Request.Url.Query ;
源代码网推荐   al = new ArrayList();
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐   public override Control FindControl(string id)
源代码网推荐   {
源代码网推荐   return base.FindControl (id);
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 重载构建子函数
源代码网推荐   ///
源代码网推荐   protected override void CreateChildControls()
源代码网推荐   {
源代码网推荐  
源代码网推荐   if(Request != null)
源代码网推荐   {
源代码网推荐   string id = string.Concat(this.ID,":"/*,this.ID,"_"*/,HIDDEN);
源代码网推荐  
源代码网推荐  
源代码网推荐   string hidden = Request[id];
源代码网推荐  
源代码网推荐   if(hidden == null || hidden == "")
源代码网推荐   return;
源代码网推荐  
源代码网推荐   string[] s = hidden.Split(",");
源代码网推荐   if(s== null || s.Length != 3 )
源代码网推荐   return;
源代码网推荐   try
源代码网推荐   {
源代码网推荐   nPage = int.Parse(s[0]);
源代码网推荐   nPageCount = int.Parse(s[1]);
源代码网推荐   nRowCount = int.Parse(s[2]);
源代码网推荐   DataBind();
源代码网推荐   }
源代码网推荐   catch
源代码网推荐   {
源代码网推荐  
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐   DataBind();
源代码网推荐   // bInit = true;
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 显示控件
源代码网推荐   ///
源代码网推荐   public override void DataBind()
源代码网推荐   {
源代码网推荐   if(bInit)
源代码网推荐   return;
源代码网推荐  
源代码网推荐   bInit = true;
源代码网推荐  
源代码网推荐   CustomInit();
源代码网推荐  
源代码网推荐  
源代码网推荐   if(ShowSearch)
源代码网推荐   AddSearch();
源代码网推荐  
源代码网推荐  
源代码网推荐   this.btnFoot_GO = new ImageButton();
源代码网推荐   this.txtFoot_Goto = new TextBox();
源代码网推荐  
源代码网推荐   //页导航
源代码网推荐   Label lcnFirst= new Label();
源代码网推荐   lcnFirst.Text = "
源代码网推荐  
源代码网推荐  ["+FirstHead+"首页"+FirstFoot+"] ["+PreHead+"前页"+PreFoot+"] ["+NextHead+"后页"+NextFoot+"] ["+LastHead+"尾页"+LastFoot+"] 第";
源代码网推荐   this.Controls.Add(lcnFirst);
源代码网推荐  
源代码网推荐   //目标页
源代码网推荐   txtFoot_Goto.Columns = 1;
源代码网推荐   txtFoot_Goto.MaxLength = 4;
源代码网推荐   txtFoot_Goto.Text = nPage.ToString();
源代码网推荐   this.Controls.Add(txtFoot_Goto);
源代码网推荐  
源代码网推荐   //总页数
源代码网推荐   Label lcnSecond = new Label();
源代码网推荐   lcnSecond.Text = "页/共"+nPageCount.ToString()+@"页("+nPageSize +@"条/页,共"+nRowCount+"条)";
源代码网推荐   this.Controls.Add(lcnSecond);
源代码网推荐  
源代码网推荐  
源代码网推荐   //go按钮
源代码网推荐   btnFoot_GO.ImageUrl = @"/Images/go.gif";
源代码网推荐   btnFoot_GO.AlternateText= "转到";
源代码网推荐   btnFoot_GO.Click += new ImageClickEventHandler(GO_Click);
源代码网推荐   this.Controls.Add(btnFoot_GO);
源代码网推荐  
源代码网推荐   // Hidden value
源代码网推荐   HtmlInputHidden hidden = new HtmlInputHidden();
源代码网推荐   hidden.ID = /*this.ID+"_"+*/HIDDEN;
源代码网推荐   hidden.Value = string.Concat(nPage,",",nPageCount,",",nRowCount);
源代码网推荐   this.Controls.Add(hidden);
源代码网推荐  
源代码网推荐   //
源代码网推荐  
源代码网推荐  
源代码网推荐   this.Controls.Add(new LiteralControl(@"
源代码网推荐  
源代码网推荐  "));
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 将搜索事件传递到容器中
源代码网推荐   ///
源代码网推荐   ///
源代码网推荐   ///
源代码网推荐   private void Search_Click(object sender, System.Web.UI.ImageClickEventArgs e)
源代码网推荐   {
源代码网推荐   if(SearchEvent != null)
源代码网推荐   SearchEvent(stxt.Text,SearchTarget.SelectedIndex);
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐   ///
源代码网推荐   /// 处理GO事件,直接重定向到目标页
源代码网推荐   ///
源代码网推荐   ///
源代码网推荐   ///
源代码网推荐   private void GO_Click(object sender, System.Web.UI.ImageClickEventArgs e)
源代码网推荐   {
源代码网推荐   //是否
源代码网推荐   if((current!="")&&(m_sIndex!= "")&&(nPageCount!= 0))
源代码网推荐   {
源代码网推荐   ChangeLink();
源代码网推荐   Response.Redirect(CurrentPage+m_sIndex+txtFoot_Goto.Text/*Request.Form[ControlName+":txtFoot_Goto"]*/ );
源代码网推荐  
源代码网推荐   }
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐   }
源代码网推荐  
源代码网推荐  
源代码网推荐  }  做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华