以前自己用过的一个分页控件 ,2.0写的 ,想让它兵刷新页面,放到updatepanel里还是刷新页面, 兵知道改怎么改进 , ?
http://download.csdn.net/source/1213151
这是我以前写的一个分页控件..虽然只是给gridView的分页的扩展..但是如果把.控制gridview的部分改成取存储过程数据..在每一个点击事件中 分页控制类 来控制分页,还是可行的。
后边的一个类是 一个用户控件分页的控制类,可以参考一下。两个合并一下,应该就是一个分页控件了。
Codeusing System;using System.Collections.Generic;using System.ComponentModel;using System.Text;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace OAWebControl{ [DefaultProperty("Text")] [ToolboxData("<{0}:PageBreakControl runat=server></{0}:PageBreakControl>")] public class PageBreakControl : WebControl, INamingContainer { private LinkButton lbtLast = new LinkButton();//末页 private LinkButton lbtNext = new LinkButton();//下一页 private LinkButton lbtPrev = new LinkButton();//上一页 private LinkButton lbtFirst = new LinkButton();//首页 private HeadGridView gridView = new HeadGridView (); private Label labInfo = new Label(); [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? String.Empty : s); } set { ViewState["Text"] = value; } } #region 属性 [DefaultValue("")] [Localizable(true)] public HeadGridView GridViewDataSoure { get { this.EnsureChildControls(); return gridView; } set { this.EnsureChildControls(); gridView = value; } } [DefaultValue("首页")] public string LbtFirst { set { lbtFirst.Text = value; } get { return lbtFirst.Text; } } [DefaultValue("末页")] public string LbtLast { set { lbtLast.Text = value; } get { return lbtLast.Text; } } [DefaultValue("上一页")] public string LbtPrev { set { lbtPrev.Text = value; } get { return lbtPrev.Text; } } [DefaultValue("下一页")] public string LbtNext { set { lbtNext.Text = value; } get { return lbtNext.Text; } } #endregion #region 触发事件 void lbtPrev_Click(object sender, EventArgs e) { if (gridView.PageIndex > 0) { gridView.PageIndex = gridView.PageIndex - 1; gridView.DataBind(); } } void lbtNext_Click(object sender, EventArgs e) { if (gridView.PageIndex < gridView.PageCount - 1) { gridView.PageIndex = gridView.PageIndex++; gridView.DataBind(); } } void lbtLast_Click(object sender, EventArgs e) { if (gridView.PageCount > 0) { gridView.PageIndex = gridView.PageCount - 1; gridView.DataBind(); } } void lbtFirs_Click(object sender, EventArgs e) { gridView.PageIndex = 0; gridView.DataBind(); } #endregion protected override void Render(HtmlTextWriter writer) { AddAttributesToRender(writer); writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1", false); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.Table); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); this.labInfo.RenderControl(writer); writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Td); this.lbtFirst.RenderControl(writer); writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Td); this.lbtPrev.RenderControl(writer); writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Td); this.lbtNext.RenderControl(writer); writer.RenderEndTag(); writer.RenderBeginTag(HtmlTextWriterTag.Td); this.lbtLast.RenderControl(writer); writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderEndTag(); } protected override void CreateChildControls() { Controls.Clear(); lbtFirst.Text = LbtFirst;//"首页"; lbtFirst.CommandArgument = "lbtFirs"; lbtFirst.Click += new EventHandler(lbtFirs_Click); lbtLast.Text = LbtLast;// "末页"; lbtLast.CommandArgument = "lbtLast"; lbtLast.Click += new EventHandler(lbtLast_Click); lbtNext.Text = LbtNext;//"下一页"; lbtNext.CommandArgument = "lbtNext"; lbtNext.Click += new EventHandler(lbtNext_Click); lbtPrev.Text = LbtPrev;//"上一页"; lbtPrev.CommandArgument = "lbtPrev"; lbtPrev.Click += new EventHandler(lbtPrev_Click); labInfo.Text = "总共" + gridView.PageCount.ToString() + "1页 当前" + (gridView.PageIndex + 1) + "页 "; this.Controls.Add(lbtFirst); this.Controls.Add(lbtLast); this.Controls.Add(lbtNext); this.Controls.Add(lbtPrev); } }}
Code/// <summary> /// 分页控制类 作者:邢少 /// </summary> [Serializable] public class DataPageView { private string _tableName; private string _fldName; private int _pageSize; private string _fieldOrder; private string _where; private int _pageCount=1; private int _currPage = 1; private DataSet _ds=new DataSet(); private string lab; private string _sort; private string _strCondition; private string _iD; private string _dist; private int _rowCount; #region 字段 /// <summary> /// 数据总行数 /// </summary> public int RowCount { get { return _rowCount; } set { _rowCount = value; } } /// <summary> /// 是否添加查询字段的 DISTINCT 默认0不添加/1添加 /// </summary> public string Dist { get { return _dist; } set { _dist = value; } } /// <summary> /// 主键 /// </summary> public string ID { get { return _iD; } set { _iD = value; } } /// <summary> /// 查询条件,不需where /// </summary> public string StrCondition { get { return _strCondition; } set { _strCondition = value; } } /// <summary> /// -排序方法,0为升序,1为降序(如果是多字段排列Sort指代最后一个排序字段的排列顺序(最后一个排序字段不加排序标记 /// </summary> public string Sort { get { return _sort; } set { _sort = value; } }/// <summary> /// 数据集 /// </summary> public DataTable DataTableView { get { DataInitializtion(); return _ds.Tables[0]; } } /// <summary> /// 分页显示的表名 /// </summary> public string TableName { get { return _tableName; } set { _tableName = value; } } /// <summary> /// 要显示的字段列表 /// </summary> public string FfldName { get { return _fldName; } set { _fldName = value; } } /// <summary> /// 每页显示的数据行 /// </summary> public int PageSize { get { return _pageSize; } set { _pageSize = value; } } /// <summary> /// 以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC用于指定排序顺序 /// </summary> public string FieldOrder { get { return _fieldOrder; } set { _fieldOrder = value; } } /// <summary> /// 查询条件 /// </summary> public string Where { get { return _where; } set { _where = value; } } /// <summary> /// 总页数 /// </summary> public int PageCount { get { return _pageCount; } } /// <summary> /// 页数信息 /// </summary> public string TablePageInfo { get { lab = "数据 " + RowCount + " 条 当前第 " + (_currPage <= _pageCount ? _currPage.ToString() : _pageCount.ToString()) + " 页 共 " + (_pageCount > 0 ? _pageCount.ToString() : "0") + " 页"; return lab; } } public int CurrPgae { get { return _currPage; } } #endregion #region 构造函数 /// <summary> /// /// </summary> /// <param name="tableName">表名</param> /// <param name="id">主键</param> /// <param name="pageSize">页面行数</param> /// <param name="fldName">要显示的字段列表</param> /// <param name="where">查询条件,不需where</param> /// <param name="sort">-排序方法,0为升序,1为降序</param> public DataPageView(string tableName, string id, int pageSize,string fldName, string where, string sort,string fieldOrder) { _iD = id; _fldName = fldName; _pageSize = pageSize; _strCondition = where; _tableName = tableName; _sort = sort; _fieldOrder = fieldOrder; //_currPage =Convert.ToInt32(curr); } public DataPageView(string[] list) { _iD = list[1]; _fldName = list[4]; _pageSize = Convert.ToInt32(list[2]); _strCondition = list[5]; _tableName = list[0]; _sort = list[6]; _fieldOrder = list[7]; _currPage = Convert.ToInt32(list[3]); } #endregion #region Methods /// <summary> /// 末页 /// </summary> public void Last() { if (_pageCount == 0) _currPage = 1; else _currPage = Convert.ToInt32(_pageCount); } /// <summary> /// 首页 /// </summary> public void Home() { _currPage = 1; } /// <summary> /// 上页 /// </summary> public void Up() { if (_currPage >1) _currPage--; } /// <summary> /// 下页 /// </summary> public void Down() { if(_currPage<_pageCount) _currPage++; } public void Goto(string currPage) { _currPage = Convert.ToInt32(currPage); } #endregion private void DataInitializtion() { ..省略 IDataParameter[] parameters ={ tbname, FieldKey, pageSize, page, fldSort, strCondition, Sort, pageCount, Counts, psFieldName2 }; _ds = DbHelperSQL.RunProcedure("", parameters, "List"); _pageCount = Convert.ToInt32(parameters[7].Value); _rowCount = Convert.ToInt32(parameters[8].Value); if (_currPage > _pageCount) _currPage = _pageCount; } }}