c#自写datalist分页面类(原创)

      还在学校时候,为了做个设计,实现datalist的分页用了好多方法来实现,单独在数据库处理的(存储过程实现),单独的功能类啊,或者一起合用啊,也都可以实现,但是还是有个单独的类实现的话还是比较简单的,以下是代码
      
None.gif using  System;
None.gif
using  System.Data;
None.gif
ExpandedBlockStart.gifContractedBlock.gif 
/**/ /// <summary>
InBlock.gif 
/// pageContral 的摘要说明。
InBlock.gif 
/// </summary>
InBlock.gif 
/// <summary>
InBlock.gif 
/// DataList分页操作类
ExpandedBlockEnd.gif 
/// </summary>

ContractedBlock.gif ExpandedBlockStart.gif   PageContral #region PageContral
InBlock.gif 
public class pageContral
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
private int m_PageNow = 1 ;  //当前页号
InBlock.gif
  private DataSet m_ds = null;  //传入的数据集合
InBlock.gif
  private int m_PageSize = 5;   //页面布局;
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 无参构造
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  public pageContral()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{}
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 有参构造
InBlock.gif  
/// </summary>
ExpandedSubBlockEnd.gif  
/// <param name="ds">传入的数据集</param>

InBlock.gif  public pageContral(DataSet ds)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DS 
= ds;   
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 有参构造
InBlock.gif  
/// </summary>
InBlock.gif  
/// <param name="ds">传入的数据集</param>
InBlock.gif  
/// <param name="pageNow">当前页</param>
ExpandedSubBlockEnd.gif  
/// <param name="pageSize">页面布局</param>

InBlock.gif  public pageContral( DataSet ds, int pageNow, int pageSize)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DS 
= ds;
InBlock.gif   PageNow 
= pageNow;
InBlock.gif   PageSize 
= pageSize;
ExpandedSubBlockEnd.gif  }
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 有参构造
InBlock.gif  
/// </summary>
InBlock.gif  
/// <param name="ds">传入的数据集</param>
ExpandedSubBlockEnd.gif  
/// <param name="pageNow">当前页面</param>

InBlock.gif  public pageContral( DataSet ds, int pageNow )
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DS 
= ds;
InBlock.gif   PageNow 
= pageNow;
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 当前页号码
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  public int PageNow 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif   
get dot.gifreturn m_PageNow; }
ExpandedSubBlockStart.gifContractedSubBlock.gif   
set dot.gif{ m_PageNow = value;}
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 传入的数据集
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  public DataSet DS 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif   
get dot.gifreturn m_ds; }
ExpandedSubBlockStart.gifContractedSubBlock.gif   
set dot.gif{ m_ds = value;}
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 页面布局
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  public int PageSize
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif   
get dot.gifreturn m_PageSize; }
ExpandedSubBlockStart.gifContractedSubBlock.gif   
set dot.gif{ m_PageSize = value;}
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 打开一页
InBlock.gif  
/// </summary>
InBlock.gif  
/// <param name="pageNo">当前页</param>
ExpandedSubBlockEnd.gif  
/// <returns>返回操作的结果</returns>

InBlock.gif  public DataSet GotePageN(int pageNo)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DataSet dsA 
= new DataSet();
InBlock.gif   dsA 
= DS.Clone();
InBlock.gif   
int a = PageCout();//获取该记录集的总条数
InBlock.gif
   if( pageNo <= a && pageNo >= 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
int rowNum = ( pageNo - 1* PageSize;
InBlock.gif    
for(int i = rowNum; i < rowNum + PageSize;i ++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if( i >= DS.Tables[0].Rows.Count)
InBlock.gif      
break;
InBlock.gif     
if( DS.Tables[0].Rows[i] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{      
InBlock.gif      dsA.Tables[
0].ImportRow((DS.Tables[0].Rows[i]) as DataRow);
ExpandedSubBlockEnd.gif     }

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
return dsA;
ExpandedSubBlockEnd.gif  }

InBlock.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 返回总页数
InBlock.gif  
/// </summary>
ExpandedSubBlockEnd.gif  
/// <returns></returns>

InBlock.gif  public int PageCout()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
int rowCount = DS.Tables[0].Rows.Count;
InBlock.gif   
int PageTemp = (int)( rowCount / m_PageSize );
InBlock.gif   
if( rowCount%m_PageSize == 0 )
InBlock.gif    
return PageTemp;
InBlock.gif   
else
InBlock.gif    
return ( PageTemp + 1 );
ExpandedSubBlockEnd.gif  }
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 下一页
InBlock.gif  
/// </summary>
InBlock.gif  
/// <param name="pageNo">当前页面</param>
ExpandedSubBlockEnd.gif  
/// <returns>返回结果</returns>

InBlock.gif  public DataSet PageNext( int pageNo )
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DataSet dsA 
= new DataSet();
InBlock.gif   dsA 
= DS.Clone();
InBlock.gif   
int a = PageCout();//获取该记录集的总条数
InBlock.gif
   if( pageNo < a)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
int rowNum = pageNo * PageSize;
InBlock.gif    
for(int i = rowNum; i < rowNum + PageSize;i ++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if( i >= DS.Tables[0].Rows.Count)
InBlock.gif      
break;
InBlock.gif     dsA.Tables[
0].ImportRow((DS.Tables[0].Rows[i]) as DataRow);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
return dsA;
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 上一页
InBlock.gif  
/// </summary>
InBlock.gif  
/// <param name="pageNo">当前页面</param>
ExpandedSubBlockEnd.gif  
/// <returns></returns>

InBlock.gif  public DataSet PageUp( int pageNo )
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DataSet dsA 
= new DataSet();
InBlock.gif   dsA 
= DS.Clone();
InBlock.gif   
int a = PageCout();//获取该记录集的总条数
InBlock.gif
   if( pageNo  >=  2 )
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
int rowNum = ( pageNo - 2 ) * PageSize;
InBlock.gif    
for(int i = rowNum; i < rowNum + PageSize;i ++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if( i >= DS.Tables[0].Rows.Count)
InBlock.gif      
break;
InBlock.gif     dsA.Tables[
0].ImportRow((DS.Tables[0].Rows[i]) as DataRow);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
return dsA;
ExpandedSubBlockEnd.gif  }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 转到首页
InBlock.gif  
/// </summary>
ExpandedSubBlockEnd.gif  
/// <returns>返回查询结果</returns>

InBlock.gif  public DataSet pageFirst()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DataSet dsA 
= new DataSet();
InBlock.gif   dsA 
= DS.Clone();
InBlock.gif   
int a = PageCout();//获取该记录集的总条数
InBlock.gif
   if( a != 0 )
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
int rowNum = 0;
InBlock.gif    
for(int i = rowNum; i < rowNum + PageSize;i ++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if( i >= DS.Tables[0].Rows.Count)
InBlock.gif      
break;
InBlock.gif     dsA.Tables[
0].ImportRow((DS.Tables[0].Rows[i]) as DataRow);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
return dsA;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 最后一页
InBlock.gif  
/// </summary>
ExpandedSubBlockEnd.gif  
/// <returns></returns>

InBlock.gif  public DataSet pageLast()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DataSet dsA 
= new DataSet();
InBlock.gif   dsA 
= DS.Clone();
InBlock.gif   
int a = PageCout();//获取该记录集的总条数
InBlock.gif
   if( a != 0 )
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
int rowNum = ( a - 1* PageSize;
InBlock.gif    
for(int i = rowNum; i < rowNum + PageSize;i ++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if( i >= DS.Tables[0].Rows.Count)
InBlock.gif      
break;
InBlock.gif     dsA.Tables[
0].ImportRow((DS.Tables[0].Rows[i]) as DataRow);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
return dsA;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif }

InBlock.gif
ExpandedBlockEnd.gif 
#endregion

None.gif
None.gif

   

转载于:https://www.cnblogs.com/wjbs7188/archive/2007/02/13/649475.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值