网上找的代码 实际应用时候一切正常就是分页无效果,只显示第一页内容 DataSet ds;
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=127.0.0.1;uid=sa;pwd=123456;database=hq");
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from telbase";
AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 15;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection("server=127.0.0.1;uid=sa;pwd=123456;database=hq");
dr = new SqlDataAdapter("select id,address,tel,username from telbase", con);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "telbase");
DataList1.DataSource = ds.Tables["telbase"];
DataList1.DataBind(); } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataListDataBind();
}
SqlDataAdapter dr;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=127.0.0.1;uid=sa;pwd=123456;database=hq");
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from telbase";
AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 15;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection("server=127.0.0.1;uid=sa;pwd=123456;database=hq");
dr = new SqlDataAdapter("select id,address,tel,username from telbase", con);
ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "telbase");
DataList1.DataSource = ds.Tables["telbase"];
DataList1.DataBind(); } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataListDataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
DataListDataBind();
}
另外Aspnetpager可以生成并调用存储过程分页的