使用AspNetPager分页的范例

很多人看了AspNetPager提供的例子,因为写得比较多其他的属性,所以在这里提供最简单的范例
 private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   //求该数据集合的记录总和
   if(!Page.IsPostBack)
   {
    SqlDataBase SqlDB=new SqlDataBase(DSN);
    string strsql="Select count(user_id) from IU_User";
    DataSet ds= SqlDB.CreateSet(strsql,"IUser");
    this.AspNetPager1.RecordCount=System.Convert.ToInt32(ds.Tables[0].Rows[0][0]) ;
    SqlDB.CloseConnection();
    BindData();
   }
  }
void BindData()
  {
   SqlDataBase SqlDB=new SqlDataBase(DSN);
   string strsql="Select User_ID, UserName, PassWord  from IU_User";
   SqlDataAdapter adapter= SqlDB.CreateAdapter(strsql);
    DataSet ds=new DataSet();
            adapter.Fill(ds,AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex-1),AspNetPager1.PageSize,"IU_User");  
   this.DataGrid1.DataSource=ds.Tables["IU_User"];
   this.DataGrid1.DataBind();
      //动态设置用户自定义文本内容
   AspNetPager1.CustomInfoText="记录总数:<font color=\"blue\"><b>"+AspNetPager1.RecordCount.ToString()+"</b></font>";
   AspNetPager1.CustomInfoText+=" 总页数:<font color=\"blue\"><b>"+AspNetPager1.PageCount.ToString()+"</b></font>";
   AspNetPager1.CustomInfoText+=" 当前页:<font color=\"red\"><b>"+AspNetPager1.CurrentPageIndex.ToString()+"</b></font>";

  }

  private void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
  {
   AspNetPager1.CurrentPageIndex=e.NewPageIndex;
   BindData();
   System.Text.StringBuilder sb=new StringBuilder("<script Language=\"Javascript\"><!--\n");
   sb.Append("var el=document.all;");
   sb.Append(this.DataGrid1.ClientID);
   sb.Append(".scrollIntoView(true);");
   sb.Append("<");
   sb.Append("/");
   sb.Append("script>");
   if(!Page.IsStartupScriptRegistered("scrollScript"))
    Page.RegisterStartupScript("scrollScript",sb.ToString());
  }

posted @ 2005-02-22 14:05  meetweb  阅读(3771)  评论(7编辑  收藏  举报