AspNetPager的用法

public partial class PagedIndex4 : System.Web.UI.Page
{  
    private Current_db db = new Current_db();
    SqlConnection conn;
    SqlCommand cmd;
    private void Page_Load(object sender, System.EventArgs e)
    {
        conn = new SqlConnection("Server = 192.168.1.15;database=my_sz5_cn;uid=skyray;pwd=skyray");

        if (!Page.IsPostBack)
        {
            cmd = new SqlCommand("select count(*) from info_information",conn);
            conn.Open();
            //设置要分页的数据的总数  
            lbtotal.Text = cmd.ExecuteScalar().ToString();
              AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();
             lbs.Text = AspNetPager1.PageSize.ToString();
            //int PageCount = AspNetPager1.RecordCount / AspNetPager1.PageSize+1;
            //lbPages.Text = PageCount.ToString();
            conn.Close();
            //绑定数据  
            BindData();
        }    
    }

    void BindData()
    {
        cmd = new SqlCommand("select top 10000 * from info_information", conn);
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        //注意下面这句,只填充当前页要显示的数据,不能把所有数据全填充到DataSet中,否则无法实现分页  
        adapter.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSiz  e, "info_information");
        GridView1.DataSource = ds.Tables["info_information"];
        GridView1.DataBind();
    }

    //翻页事件处理程序,设置分页控件的当前页索引并重新绑定数据
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindData();
    }
}

posted @ 2007-08-17 14:15 tianya 阅读(954) 评论(0)  编辑 收藏

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  博客园首页

  新闻频道

  社区

  小组

  博问

  网摘

  闪存

  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: