DataGrid自定义分页控件WebControl

该博客为转载内容,转载自https://www.cnblogs.com/tanjunmail/archive/2005/08/15/215090.html ,原内容可能与JavaScript和UI相关。
用了DataGrid控件很长时间,觉得分页功能有限,比如,没有共有多少条记录的提示、定位到底第几页等等,可以用WebControl 模拟出来,但是每次用都需要拷贝同样的代码很繁琐,本人很懒,所决定写一个控件来解决,命名为DataGridNavigator;
代码如下:
None.gifusing System;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.ComponentModel;
None.gif
using System.Collections.Specialized;
None.gif
using System.Collections;
None.gif
using System.Data;
None.gif
using System.Text;
None.gif
using System.Reflection;
None.gif
None.gif
namespace HTCL.DataControl
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// OnClick事件参数。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class DataNavigatorClickEventArgs : EventArgs
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
int _currentpageindex;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// DataGrid当前页索引号。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public int CurrentPageIndex
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _currentpageindex; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 初始化一个新的DataNavigatorClickEventArgs实例。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="currentpageindex">当前页索引号</param>

InBlock.gif        public DataNavigatorClickEventArgs(int currentpageindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _currentpageindex 
= currentpageindex;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// DataNavigtor鼠标点击事件委托声明
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public delegate void ClickEventHandler(object sender, DataNavigatorClickEventArgs e);
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// DataNavigator 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [DefaultProperty("Text"), 
InBlock.gif        ToolboxData(
"<{0}:DataNavigator runat=server></{0}:DataNavigator>")]
InBlock.gif    
public class DataGridNavigator : System.Web.UI.WebControls.WebControl,IPostBackEventHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
//        private string text;
InBlock.gif
//        private int _pagecount, _currentpageindex, _totalrecord, _pagesize;
InBlock.gif
        private System.Web.UI.WebControls.DataGrid _datagrid;
InBlock.gif        
private DataSet _dataset;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当“首页”链接被点击时,事件产生。.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        //[ResDescription("FirstPageClick")]
InBlock.gif
        public event ClickEventHandler FirstPageClick;
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当“上一页”链接被点击时,事件发生。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        //[ResDescription("PreviousPageClick")]
InBlock.gif
        public event ClickEventHandler PreviousPageClick;
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当“下一页”链接被点击时,事件发生。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        //[ResDescription("NextPageClick")]
InBlock.gif
        public event ClickEventHandler NextPageClick;
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当“末页”链接被点击时,事件发生。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        //[ResDescription("LastPageClick")]
InBlock.gif
        public event ClickEventHandler LastPageClick;
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当“Go”链接被点击时,事件发生。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        //[ResDescription("GotoPageClick")]
InBlock.gif
        public event ClickEventHandler GotoPageClick;
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 显示错误信息对话框。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="Message">错误信息</param>

InBlock.gif        private void ShowMessage(string Message)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(!this.Page.IsStartupScriptRegistered("DataNavigatorError"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                StringBuilder sb 
= new StringBuilder();
InBlock.gif            
InBlock.gif                sb.Append(
"<script language=javascript>\n");
InBlock.gif                sb.Append(
"window.alert('" + Message + "');\n");
InBlock.gif                sb.Append(
"</script>");
InBlock.gif            
InBlock.gif                
this.Page.RegisterStartupScript("DataNavigatorError",sb.ToString());
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当点击“首页”链接时被访问。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="e">事件参数</param>

InBlock.gif        protected virtual void OnFirstPageClick(DataNavigatorClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (FirstPageClick != null)
InBlock.gif                FirstPageClick(
this, e);
InBlock.gif            CurrentPageIndex 
= 0;
InBlock.gif            DataGridDataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当点击“上一页”链接时被访问。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="e">事件参数</param>

InBlock.gif        protected virtual void OnPreviousPageClick(DataNavigatorClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (PreviousPageClick != null)
InBlock.gif                PreviousPageClick(
this, e);
InBlock.gif            CurrentPageIndex 
--;
InBlock.gif            DataGridDataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当点击“下一页”链接时被访问
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="e">事件参数</param>

InBlock.gif        protected virtual void OnNextPageClick(DataNavigatorClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (NextPageClick != null)
InBlock.gif                NextPageClick(
this, e);
InBlock.gif            CurrentPageIndex 
++;
InBlock.gif            DataGridDataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当点击“末页”链接时被访问
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="e">事件参数</param>

InBlock.gif        protected virtual void OnLastPageClick(DataNavigatorClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (LastPageClick != null)
InBlock.gif                LastPageClick(
this, e);
InBlock.gif            CurrentPageIndex 
= PageCount - 1;
InBlock.gif            DataGridDataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 当点击“Go”链接时被访问
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="e">事件参数</param>

InBlock.gif        protected virtual void OnGotoPageClick(DataNavigatorClickEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (GotoPageClick != null)
InBlock.gif                GotoPageClick(
this,e);
InBlock.gif
InBlock.gif            
if ((e.CurrentPageIndex >= 0 ) & (e.CurrentPageIndex < PageCount))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                CurrentPageIndex 
= e.CurrentPageIndex;
InBlock.gif                DataGridDataBind();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// Enables a server control to process an event raised when a form is posted to server.
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="eventArgument"></param>

InBlock.gif        public virtual void RaisePostBackEvent(string eventArgument)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int temp;
InBlock.gif            
switch(eventArgument)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                    
// 点击的“首页”链接
InBlock.gif
                case"FirstPage":
InBlock.gif                    
this.OnFirstPageClick(new DataControl.DataNavigatorClickEventArgs(0));
InBlock.gif                    
break;
InBlock.gif                    
// 点击的“上一页”链接
InBlock.gif
                case "PreviousPage":
InBlock.gif                    
this.OnPreviousPageClick(new DataControl.DataNavigatorClickEventArgs(CurrentPageIndex));
InBlock.gif                    
break;
InBlock.gif                    
// 点击的“下一页”链接
InBlock.gif
                case "NextPage":
InBlock.gif                    
this.OnNextPageClick(new DataControl.DataNavigatorClickEventArgs(CurrentPageIndex));
InBlock.gif                    
break;
InBlock.gif                    
// 点击的“末页”链接
InBlock.gif
                case "LastPage":
InBlock.gif                    
this.OnLastPageClick(new DataControl.DataNavigatorClickEventArgs(PageCount));
InBlock.gif                    
break;
InBlock.gif                    
// 点击的“Go”链接
InBlock.gif
                default:
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        temp 
= System.Convert.ToInt32(eventArgument);    
InBlock.gif                        
if ((temp < 1| (temp > PageCount))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
this.ShowMessage("页数超出范围!");
InBlock.gif                            
return;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            temp 
--;
InBlock.gif                            CurrentPageIndex 
= temp;
InBlock.gif                            OnGotoPageClick(
new DataControl.DataNavigatorClickEventArgs(CurrentPageIndex));
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch(Exception)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this.ShowMessage("请输入数字!");
InBlock.gif                    
ExpandedSubBlockEnd.gif                    }
                    
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [Bindable(
false),
InBlock.gif        Category(
"Data"),
InBlock.gif        DefaultValue(
"")]
InBlock.gif        
public System.Web.UI.WebControls.DataGrid DataGrid
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return (DataGrid)_datagrid;
InBlock.gif
//                return (DataGrid)this.ViewState["NavigatorDataGrid"];
ExpandedSubBlockEnd.gif
            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{            
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _datagrid 
= value; 
InBlock.gif
//                    this.ViewState["NavigatorDataGrid"] = value;
InBlock.gif
                    CurrentPageIndex = _datagrid.CurrentPageIndex;
InBlock.gif                    PageCount 
= _datagrid.PageCount;
InBlock.gif                    PageSize 
= _datagrid.PageSize;
InBlock.gif                    CurrentPageSize 
= _datagrid.Items.Count;
InBlock.gif                    
if (DataGrid.DataSource!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        TotalRecord 
= 0;
InBlock.gif                        DataSet dataset 
= (DataSet)DataGrid.DataSource;
InBlock.gif                        
if (DataGrid.DataMember != string.Empty)
InBlock.gif                            TotalRecord 
= dataset.Tables[DataGrid.DataMember].Rows.Count;
InBlock.gif                        
else
InBlock.gif                            TotalRecord 
= dataset.Tables[0].Rows.Count;
ExpandedSubBlockEnd.gif                    }
    
ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch(Exception ee)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    ShowMessage(ee.Message);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Bindable(
false),
InBlock.gif        Category(
"Data"),
InBlock.gif        DefaultValue(
"")]
InBlock.gif        
public System.Data.DataSet DataGridDataSet
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (DataSet)_dataset;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (value != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                
InBlock.gif                    _dataset 
= value; 
InBlock.gif                    
if(((DataGrid)_datagrid).DataMember != string.Empty)
InBlock.gif                        TotalRecord 
= _dataset.Tables[DataGrid.DataMember].Rows.Count;
InBlock.gif                    
else
InBlock.gif                        TotalRecord 
= _dataset.Tables[0].Rows.Count;                    
InBlock.gif    
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        [Bindable(
false),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"")]
InBlock.gif        
public int CurrentPageIndex
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (int)ViewState["CurrentPageIndex"]; 
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"CurrentPageIndex"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [Bindable(
false),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"")]
InBlock.gif        
public int PageCount
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (int)ViewState["PageCount"]; 
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"PageCount"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [Bindable(
false),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"")]
InBlock.gif        
public int TotalRecord
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (int)ViewState["TotalRecord"];
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"TotalRecord"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [Bindable(
false),
InBlock.gif        Category(
"Appearance"),
InBlock.gif        DefaultValue(
"")]
InBlock.gif        
public int PageSize
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (int)ViewState["PageSize"]; 
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"PageSize"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public int CurrentPageSize
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (int)ViewState["CurrentPageSize"];
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"CurrentPageSize"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        [Bindable(
true), 
InBlock.gif            Category(
"Appearance"), 
InBlock.gif            DefaultValue(
"")] 
InBlock.gif        
public string Text 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (string)ViewState["Text"];
ExpandedSubBlockEnd.gif            }

InBlock.gif 
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"Text"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void DataGridDataBind()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (DataGrid != null)            
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DataGrid.EditItemIndex 
= -1;
InBlock.gif                DataGrid.CurrentPageIndex 
= CurrentPageIndex;
InBlock.gif                
if (DataGrid.DataMember == string.Empty)
InBlock.gif                    DataGrid.DataMember 
= this.DataGridDataSet.Tables[0].TableName;
InBlock.gif                DataGrid.DataBind();                
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 将此控件呈现给指定的输出参数。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="output"> 要写出到的 HTML 编写器 </param>

InBlock.gif        protected override void Render(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string script = "<script type=""text/javascript"">";
InBlock.gif            script 
+= "function gettext(){ return document.all['GoToTextBox'].value;}";
InBlock.gif            script 
+= "</script>"
InBlock.gif            
InBlock.gif            output.Write(script);
InBlock.gif            output.Write(
"共有"+TotalRecord.ToString()+"记录");
InBlock.gif            output.Write(
"&nbsp;");
InBlock.gif            
if (CurrentPageIndex == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.Write(
"上一页&nbsp;下一页&nbsp;");
InBlock.gif                output.Write(
"&nbsp;");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.Write(
"<a  href=javascript:"+this.Page.GetPostBackClientEvent(this,"FirstPage")+">上一页</a>");
InBlock.gif                output.Write(
"&nbsp;");
InBlock.gif                output.Write(
"<a  href=javascript:"+this.Page.GetPostBackClientEvent(this,"PreviousPage")+">下一页</a>");
InBlock.gif                output.Write(
"&nbsp;");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
if (CurrentPageIndex < PageCount-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.Write(
"<a class='NextPgBtn' href=javascript:"+this.Page.GetPostBackClientEvent(this,"NextPage")+"></a>");
InBlock.gif                output.Write(
"&nbsp;");
InBlock.gif                output.Write(
"<a class='LastPgBtn' href=javascript:"+this.Page.GetPostBackClientEvent(this,"LastPage")+"></a>");
InBlock.gif                output.Write(
"&nbsp;");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
InBlock.gif                output.Write(
"下一页&nbsp;末页&nbsp;");
InBlock.gif
InBlock.gif            output.Write(
"&nbsp;&nbsp;转到&nbsp;");
InBlock.gif            output.Write(
"<input");
InBlock.gif            
if (PageCount == 1)
InBlock.gif                output.Write(
" disabled = 'disabled' ");
InBlock.gif            output.Write(
" Type=Text Name=GoToTextBox ");
InBlock.gif            
int temp = CurrentPageIndex + 1;
InBlock.gif            output.Write(
" value = "+temp.ToString());
InBlock.gif            output.Write(
" size = 2>");
InBlock.gif            output.Write(
"/"+PageCount.ToString()+"");
InBlock.gif            output.Write(
"&nbsp;&nbsp;");
InBlock.gif            output.Write(
"<input Type=Button Name=GoToButton  value = 定位 onclick = javascript:__doPostBack('"+this.ID+"',gettext())>");
InBlock.gif            output.Write(
"&nbsp;&nbsp;");
InBlock.gif            output.Write(
"每页"+CurrentPageSize.ToString()+"/"+PageSize.ToString()+"条记录");
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public  DataGridNavigator()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            CurrentPageIndex 
= 0;
InBlock.gif            PageCount 
= 0;
InBlock.gif            TotalRecord 
= 0;
InBlock.gif            PageSize 
= 0;
InBlock.gif            CurrentPageSize 
= 0;
InBlock.gif            Text 
= "";
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
但是,每页刷新的时候,DataGrid和DataSet需要重新付值,这个问题写个版本在解决吧,呵呵,这个我做的第一个DotNet控件!

转载于:https://www.cnblogs.com/tanjunmail/archive/2005/08/15/215090.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值