repeater绑定AspNetPage分页效果不出来。是为什么?
2个回答
展开全部
Repeater1.DataSource = ds.Tables[0];
Repeater1.DataBind();
PagedDataSource pds = new PagedDataSource();
AspNetPagerAccount.RecordCount = ds.Tables[0].DefaultView.Count;
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPagerAccount.CurrentPageIndex - 1;
pds.PageSize = AspNetPagerAccount.PageSize;
Repeater1.DataSource = pds;
Repeater1.DataBind();
Repeater2.DataSource = ds.Tables[0];
Repeater2.DataBind();
大概的代码是这样的 你可以参考下
Repeater1.DataBind();
PagedDataSource pds = new PagedDataSource();
AspNetPagerAccount.RecordCount = ds.Tables[0].DefaultView.Count;
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPagerAccount.CurrentPageIndex - 1;
pds.PageSize = AspNetPagerAccount.PageSize;
Repeater1.DataSource = pds;
Repeater1.DataBind();
Repeater2.DataSource = ds.Tables[0];
Repeater2.DataBind();
大概的代码是这样的 你可以参考下
展开全部
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databind();
}
}
private void databind()
{
SqlConnection conn;
DataSet ds;
//创建数据库连接对象
using (conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString))
{
//打开连接对象
conn.Open();
//定义sql语句
string sql = "select * from Tbl_Users";
//创建适配器
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
//创建数据集
ds = new DataSet();
//填充数据集
sda.Fill(ds, "channel");
}
conn.Close();
AspNetPager1.PageSize = 5;
AspNetPager1.RecordCount = ds.Tables["channel"].Rows.Count;
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["channel"].DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
Repeater1.DataSource = pds;
Repeater1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
databind();
}
{
if (!IsPostBack)
{
databind();
}
}
private void databind()
{
SqlConnection conn;
DataSet ds;
//创建数据库连接对象
using (conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString))
{
//打开连接对象
conn.Open();
//定义sql语句
string sql = "select * from Tbl_Users";
//创建适配器
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
//创建数据集
ds = new DataSet();
//填充数据集
sda.Fill(ds, "channel");
}
conn.Close();
AspNetPager1.PageSize = 5;
AspNetPager1.RecordCount = ds.Tables["channel"].Rows.Count;
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["channel"].DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
Repeater1.DataSource = pds;
Repeater1.DataBind();
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
databind();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询