aspnetpager 分页无效果

[复制链接]
查看11 | 回复1 | 2008-6-12 09:30:27 | 显示全部楼层 |阅读模式
protected void Button1_Click(object sender, EventArgs e)

{



SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString.ToString());

con.Open();

com = new SqlCommand();

com.Connection = con;

com.CommandText = "SELECT * FROM dbo.hbase where nullb=1 and tel like '%" + this.dhhm.Text + "%' order by tel";

AspNetPager1.AlwaysShow = true;

AspNetPager1.PageSize = 15;

AspNetPager1.RecordCount = (int)com.ExecuteScalar();

con.Close();

DataListDataBind1();
}

private void DataListDataBind1()

{

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString.ToString());
dr = new SqlDataAdapter("SELECT * FROM dbo.hbase where nullb=1 and tel like '%" + this.dhhm.Text + "%' order by tel", con);

ds = new DataSet();

dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "hbase");

DataList1.DataSource = ds.Tables["hbase"];

DataList1.DataBind();

}

protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)

{

AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataListDataBind1();

}
分页只显示第一页,谁帮帮我
page_load 里面米内容

回复

使用道具 举报

千问 | 2008-6-12 09:30:27 | 显示全部楼层
我不知道你page_load里面执行的是什么 但如果你一上来就绑定DataListDataBind1()这个方法的话AspNetPager1.RecordCount = (int)com.ExecuteScalar(); 这个要出现在DataListDataBind1()方法前面 也就是说 要先得到RecordCount值
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行