带搜索的分页控件之1

时间:2010-02-25 17:23:39  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:****************************************/ 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 { /// //...
  正文:* 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.ASP/ target=_blank class=infotextkey>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
"带搜索的分页控件之1"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/aspnet/12899.html


关键字:

关于《带搜索的分页控件之1》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td