关于分页控件绑定数据的问题
源代码:private void BindUserList()
{
//int cup = Convert.ToInt32(this.lb_CurrentPage.Text);
PagedDataSource ps = new PagedDataSource();
ps.DataSource = Anwerbeformularbll.GetAnwerbeformular();
ps.AllowPaging = true; ps.PageSize = 10;
//每页显示的数据的行数
//ps.CurrentPageIndex = cup - 1;
//lb_count.Text = ps.DataSourceCount.ToString(); //获取记录总数
//lb_page.Text = ps.PageCount.ToString(); //获取总页数
int CurPage;
if (Request.QueryString["Page"] != null && Request.QueryString["Page"] != "0")
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
ps.CurrentPageIndex = CurPage - 1;
int Counts = ps.PageCount;
labPage.Text = "共 " + Counts.ToString() + " 页";
if (!ps.IsFirstPage && !ps.IsLastPage)
{
first.Visible = true;
first.Enabled = true;
last.Visible = true;
last.Enabled = true;
next.Visible = true;
next.Enabled = true;
up.Visible = true;
up.Enabled = true;
this.first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
this.last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(Counts);
up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
next.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
lb_Currentpage.Text = CurPage.ToString();
}
else if (!ps.IsFirstPage && ps.IsLastPage)
{
last.Visible = false;
last.Enabled = false;
up.Visible = true;
up.Enabled = true;
next.Visible = false;
next.Enabled = false;
this.first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
lb_Currentpage.Text = CurPage.ToString();
}
else if (ps.IsFirstPage && !ps.IsLastPage)
{
first.Visible = false;
first.Enabled = false;
next.Visible = true;
next.Enabled = true;
up.Visible = false;
up.Enabled = false;
this.last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(Counts);
next.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
lb_Currentpage.Text = CurPage.ToString();
}
else
{
first.Visible = false;
first.Enabled = false;
next.Visible = false;
next.Enabled = false;
up.Visible = false;
up.Enabled = false;
last.Visible = false;
last.Enabled = false;
}
UserList.DataSource = ps;
UserList.DataBind();
}
现在我想通过点击页面上面的按钮,进行有条件的筛选,但是这个页面数据绑定上面会有问题
比如一页中,最多显示15个数据,但是我查出来有16条,按照正常的话,我点下一页,应该就能看到第16条数据了,但是现在我一点下一页,数据又会因为绑定的问题,变成未点击按钮前的样子
现在我想根据筛选出来的值,在重新绑定数据,应该就可以解决掉了,但是不会写,希望大家帮我看下怎么改好哦 --------------------编程问答-------------------- 参考
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();
}
补充:.NET技术 , ASP.NET