分页的输入页数跳转和当前第几页功能合并怎么做
public partial class Test: System.Web.UI.Page
{
protected int pageSize = 10;//规定每页显示的条数
protected int pageIndex = 1;//默认是第一页
protected int pageCount = 1;//一共多少页
protected bool flag = false;//尾页标志
protected void Page_Load(object sender, EventArgs e)
{
fenye();
}
/// <summary>
/// 绑定Repeater
/// </summary>
private void dataGrid()
{
//每页记录数
if (text1.Value.Trim() != "")
pageSize = Int32.Parse(text1.Value);
//绑定
Repeater1.DataSource = DB.Proccommand("表名", "显示字段", "排列字段名", "where条件", pageSize, pageIndex);
Repeater1.DataBind();
}
/// <summary>
/// 分页方法
/// </summary>
private void fenye()
{
if (Request.QueryString["pageIndex"] != null && Request.QueryString["pageIndex"] != "" && pageIndex != 1)
{
pageIndex = Int32.Parse(Request.QueryString["pageIndex"]);
}
if (flag)
pageIndex = pageCount;
dataGrid();
//如果是第一页,上一页的链接要失效;最后一页,下一页的链接要失效
this.butProv.Enabled = true;
this.butNext.Enabled = true;
if (pageIndex <= 1)
this.butProv.Enabled = false;
if (pageIndex >= pageCount)
this.butNext.Enabled = false;
this.butProv.PostBackUrl =
String.Format("Schcode.aspx?pageIndex={0}", pageIndex - 1);
this.butNext.PostBackUrl =
String.Format("Schcode.aspx?pageIndex={0}", pageIndex + 1);
}
//首页
protected void butFisrt_Click(object sender, EventArgs e)
{
pageIndex = 1;
fenye();
}
//上一页
protected void butProv_Click(object sender, EventArgs e)
{
pageIndex = pageIndex - 1;
this.fenye();
}
//下一页
protected void butNext_Click(object sender, EventArgs e)
{
pageIndex = pageIndex + 1;
this.fenye();
}
//尾页
protected void butSecond_Click(object sender, EventArgs e)
{
flag = true;
fenye();
}
/// <summary>
/// 确定按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button6_Click(object sender, EventArgs e)
{
//跳转到第几页
if (text2.Value.Trim() != "")
{
pageIndex = int.Parse(text2.Value);
if (pageIndex >= pageCount)
flag = true;
if (pageIndex <= 0)
pageIndex = 1;
}
else
{
pageIndex = 1;
}
fenye();
}
}
text2填入数字按确定后能够跳转到那一页,但同时我也想在text2上显示当前是第几页
我试过,把当前页数pageInde赋值给text2,但是这又会影响它的跳转功能
上面的代码是没赋值的情况,只能够正常使用跳转,究竟要怎么样才可以让text2既可以显示当前第几页又可以跳转页面