日期:2014-05-18  浏览次数:20407 次

Datalist控件分页问题
有一vs2003.net做的datalist分页页面,如100条记录,pagesize=10时,显示共10页,但每页只显示5条记录
pagesize=5时每页显示3条记录,只有在pagesize=1时才正确。
datalist设置:RepeatColumns= "1 "

--------------------------------------
相关源码:

#region   公共属性

public   int   ItemCount
{
get   {   return   Convert.ToInt32(ViewState[ "ITEMCOUNT "]);   }
set   {   ViewState[ "ITEMCOUNT "]   =   value;   }
}

public   int   PageCount
{
get   {   return   Convert.ToInt32(ViewState[ "PAGECOUNT "]);   }
set   {   ViewState[ "PAGECOUNT "]   =   value;   }
}

public   int   CurrentPage
{
get
{
if   (ViewState[ "PAGE "]   !=   null)
{
return   Convert.ToInt32(ViewState[ "PAGE "]);
}
else
{
return   1;
}
}
set   {   ViewState[ "PAGE "]   =   value;   }
}

#endregion

private   void   DataGridBind()
{
DataView   dv   =   GetDataSource();

dv.RowFilter   =   InitQuery();
ItemCount   =   dv.Count;

PagedDataSource   pds   =   new   PagedDataSource();
pds.DataSource   =   dv;
pds.AllowPaging   =   true;
pds.PageSize   =   10;
pds.CurrentPageIndex   =   CurrentPage   -   1;
PageCount   =   pds.PageCount;

try
{
dlCADStyleMaster.DataSource   =   pds;
dlCADStyleMaster.DataBind();
}
catch
{
this.DataGridBind();
}
}


private   void   dlCADStyleMaster_ItemCommand(object   source,   System.Web.UI.WebControls.DataListCommandEventArgs   e)
{
if   (e.CommandName   ==   "首页 ")
{
CurrentPage   =   1;
DataGridBind();
}
if   (e.CommandName   ==   "前十页 ")
{
CurrentPage   =   CurrentPage   -   10;
DataGridBind();
}
if   (e.CommandName   ==   "上一页 ")
{
CurrentPage   --;
DataGridBind();
}
if   (e.CommandName   ==   "下一页 ")
{
CurrentPage   ++;
DataGridBind();
}
if   (e.CommandName   ==   "后十页 ")
{
CurrentPage   =   CurrentPage   +   10;
DataGridBind();
}
if   (e.CommandName   ==   "末页 ")
{
CurrentPage   =   PageCount;
DataGridBind();
}
}

private   void   cmdSearch_Click(object   sender,   System.EventArgs   e)
{
CurrentPage   =   1;
DataGridBind();
}

private   void   dlCADStyleMaster_ItemCreated(object   sender,   System.Web.UI.WebControls.DataListItemEventArgs   e)
{
if   (e.Item.ItemType   ==   ListItemType.Header   ||   e.Item.ItemType   ==   ListItemType.Footer)
{
Label   Space   =   new   Label();
Label   PageStyleI