protected System.Web.UI.WebControls.DataList dlThis ;
private static Client client =new Client() ; //自己写的类
public PagedDataSource PdsData ;private void dlThisDataBinding()
{
DataSet  ds =client.ThisDataSet ;PdsData = new PagedDataSource() ;
PdsData.AllowPaging= true  ;
PdsData.DataSource= ds.Tables["clients"].DefaultView ;
PdsData.PageSize = 5 ;
//从session获取要显示的页数
PdsData.CurrentPageIndex = Convert.ToInt32(Session["index"]) ;
ViewState.Add("pageCount", PdsData.PageCount );
dlThis.DataSource = PdsData ; 
//把分页对象Binding到DataList控件上
dlThis.DataBind() ;
}

private void Page_Load(object sender, System.EventArgs e)
{

if(! Page.IsPostBack )  dlThisDataBinding() ; //调用Binding方法}
private void dlThis_ItemCommand(object source, 
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
dlThis.SelectedIndex = e.Item.ItemIndex ;
if(e.Item.ItemType==ListItemType.Footer)
{
string actionText = e.CommandName ;
int index =Convert.ToInt32(Session["index"]) ;
                //从Session那里获取当前的页数

if( actionText =="first")
{
Session["index"] = 0 ;
}
else if( actionText =="ahead")
{
      Session["index"] =--index;
}
else if( actionText =="next")
{
Session["index"] =++index ;
}
else if( actionText =="last")
{
     Session["index"] = Convert.ToInt32(ViewState["pageCount"])-1 ;
} }
dlThisDataBinding() ; //问题在这里
// 如果有了这句下面在FooterTemplate中的控件无法被禁用,反之就可以起作用
((Button)e.Item.FindControl("btnPageFirst")).Enabled= false ;