public
PagedDataSource GetPagedDataSource(DataSet MyDataSet,
int
PageSize,
int
PageNum,
string
AspxName,Label PageLable)
{
PagedDataSource PDS = new PagedDataSource();
PDS.AllowPaging = true ;
PDS.PageSize = PageSize;
PDS.DataSource = MyDataSet.Tables[ 0 ].DefaultView;
int CurrentPage = 0 ;
if (Convert.ToString(PageNum) != null )
{
CurrentPage = int .Parse(PageNum.ToString());
}
else
{
CurrentPage = 1 ;
}
PDS.CurrentPageIndex = CurrentPage - 1 ;
int PageCount = PDS.PageCount;
string FirstPage = (PageNum == 1 ) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >9</font> " ):( " <a href= " + AspxName + " page=1><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >9</font></a> " );
string PrevPage = (PageNum == 1 ) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >7</font> " ):( " <a href= " + AspxName + " page= " + (PageNum - 1 ) + " ><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >7</font></a> " );
string NextPage = (PageNum == (PageCount)) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >8</font> " ):( " <a href= " + AspxName + " page= " + (PageNum + 1 ) + " ><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >8</font></a> " );
string LastPage = (PageNum == (PageCount)) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >:</font> " ):( " <a href= " + AspxName + " page= " + PageCount + " ><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >:</font></a> " );
PageLable.Text = " <span style=\ " float :right; " +Show+ " \ " >总记录: " + PDS.DataSourceCount + " 每页: " + PageSize + " 总页数: " + PageCount + " </span><span style=\ " float :left\ " > " + FirstPage + " " + PrevPage + " " + NextPage + " " + LastPage + " </span> " ;
return PDS;
}
{
PagedDataSource PDS = new PagedDataSource();
PDS.AllowPaging = true ;
PDS.PageSize = PageSize;
PDS.DataSource = MyDataSet.Tables[ 0 ].DefaultView;
int CurrentPage = 0 ;
if (Convert.ToString(PageNum) != null )
{
CurrentPage = int .Parse(PageNum.ToString());
}
else
{
CurrentPage = 1 ;
}
PDS.CurrentPageIndex = CurrentPage - 1 ;
int PageCount = PDS.PageCount;
string FirstPage = (PageNum == 1 ) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >9</font> " ):( " <a href= " + AspxName + " page=1><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >9</font></a> " );
string PrevPage = (PageNum == 1 ) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >7</font> " ):( " <a href= " + AspxName + " page= " + (PageNum - 1 ) + " ><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >7</font></a> " );
string NextPage = (PageNum == (PageCount)) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >8</font> " ):( " <a href= " + AspxName + " page= " + (PageNum + 1 ) + " ><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >8</font></a> " );
string LastPage = (PageNum == (PageCount)) ? ( " <font face=\ " webdings\ " style=\ " color:# 999 ;font - size:12px ! important\ " >:</font> " ):( " <a href= " + AspxName + " page= " + PageCount + " ><font face=\ " webdings\ " style=\ " font - size:12px ! important\ " >:</font></a> " );
PageLable.Text = " <span style=\ " float :right; " +Show+ " \ " >总记录: " + PDS.DataSourceCount + " 每页: " + PageSize + " 总页数: " + PageCount + " </span><span style=\ " float :left\ " > " + FirstPage + " " + PrevPage + " " + NextPage + " " + LastPage + " </span> " ;
return PDS;
}
调用示例
//
PagedDataSource分页
string MySql = " Select * from C_Company " ;
int PageNum = (Request.QueryString[ " Page " ] == null ) ? ( 1 ):(Convert.ToInt32(Request.QueryString[ " Page " ]));
MyDataSet = MyData.GetDataSet(MySql, 0 , 0 , " Table " );
PagedDataSource PDS = new PagedDataSource();
PDS = MyData.GetPagedDataSource(MyDataSet, 10 ,PageNum,Request.CurrentExecutionFilePath + " ? " ,Label1);
this .DataGrid1.DataSource = PDS;
this .DataGrid1.DataBind();
string MySql = " Select * from C_Company " ;
int PageNum = (Request.QueryString[ " Page " ] == null ) ? ( 1 ):(Convert.ToInt32(Request.QueryString[ " Page " ]));
MyDataSet = MyData.GetDataSet(MySql, 0 , 0 , " Table " );
PagedDataSource PDS = new PagedDataSource();
PDS = MyData.GetPagedDataSource(MyDataSet, 10 ,PageNum,Request.CurrentExecutionFilePath + " ? " ,Label1);
this .DataGrid1.DataSource = PDS;
this .DataGrid1.DataBind();