repeater分页部分代码问题
public void Bind2()
{
string connectionString = ConfigurationManager.ConnectionStrings["db_health"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
string sql = "select * from health_user_followup_content where user_id="+userId+"";
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
sda.Fill(ds);
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = 5;
Session["max"] = pds.PageCount;
pds.CurrentPageIndex = (int)Session["cp"];
this.rpUserList.DataSource = pds;
this.rpUserList.DataBind();
conn.Close();
}
我是想做一个分页功能 这段话能实现在repeater页面中显示出内容的功能吗?,我运行后this.rpUserList.DataBind();句话提示未将对象引用实例,这个是从网上查的,我想加入到我的程序中实现repeater分页功能
------解决方案--------------------
那就直接复制, 直接用 就像拖个控件一下简单。
protected void Page_Load(object sender, EventArgs e)
{
dlBind();
}
public void dlBind()
{
int curpage = Convert.ToInt32(this.labPage.Text);
PagedDataSource ps = new PagedDataSource();
sqlconn = myCon.getCon();
sqlconn.Open();
string sqlstr = "select a.*,b.* from tb_Card as a join tb_Module as b on a.ModuleID=b.ModuleID";
SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, sqlconn);
DataSet ds = new DataSet();
MyAdapter.Fill(ds, "tb_Card");
ps.DataSource = ds.Tables["tb_Card"].DefaultView;
ps.AllowPaging = true; //是否可以分页
ps.PageSize = 2; //显示的数量
ps.CurrentPageIndex = curpage - 1; //取得当前页的页码
this.lnkbtnUp.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
this.lnkbtnOne.Enabled = true;
if (curpage == 1)
{
this.lnkbtnOne.Enabled = false;//不显示第一页按钮
this.lnkbtnUp.Enabled = false;//不显示上一页按钮
}
if (curpage == ps.PageCount)
{
this.lnkbtnNext.Enabled = false;//不显示下一页
this.lnkbtnBack.Enabled = false;//不显示最后一页
}
this.labBackPage.Text = Convert.ToString(ps.PageCount);
this.dlContent.DataSource = ps;
this.dlContent.DataKeyField = "CardID";
this.dlContent.DataBind();
}
protected void lnkbtnOne_Click(object sender, EventArgs e)
{
this.labPage.Text = "1";
this.dlBind();
}
protected void lnkbtnUp_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) - 1);
this.dlBind();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
this.dlBind();
}
protected void lnkbtnBack_Click(object sender, EventArgs e)
{
this.labPage.Text = this.labBackPage.Text;
this.dlBind();
}
------解决方案--------------------参考一下aspnetpagere+repeater分页吧:
http://www.cnblogs.com/cqchai/archive/2011/05/25/2057531.html