本人自写代码(Aspnetpager详细介绍)

DataSet ds;
    SqlDataAdapter dr;
    SqlCommand com;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shanxiConnectionString"].ConnectionString);
            com = new SqlCommand("select count(*) from Artist",con);
            con.Open();
            AspNetPager1.RecordCount=(int)com.ExecuteScalar();
       
            con.Close();
            bind();
        }
    }

    public void bind()
    {


        int count = (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize;
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shanxiConnectionString"].ConnectionString);
        dr = new SqlDataAdapter("select * from Artist", con);
        ds = new DataSet();
        dr.Fill(ds, count, AspNetPager1.PageSize, "Artist");
      
        GridView1.DataSource = ds.Tables["Artist"];
        GridView1.DataBind();
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bind();
    }

你可能感兴趣的:(PAGER)