为什么我每次点下一页或最后一页时,当前页的显示都是显示上一次操作的页码,我的代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(Request["news_type"]!=null){
string infor_type = Request["news_type"].ToString();
SqlConnection mycon = SqlHelper.sqlcon();
mycon.Open();
string str = "select count(*) from 信息 where 信息类型='"+infor_type+"'";
SqlCommand mycom = new SqlCommand(str, mycon);
AspNetPager1.RecordCount = (int)mycom.ExecuteScalar();
AspNetPager1.CustomInfoHTML = "记录总数:<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoHTML += " 总页数:<font color='blue'><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
Bind();
}
}
}
private void Bind()
{
if (Request["news_type"] != null)
{
string infor_type1 = Request["news_type"].ToString();
SqlConnection mycon = SqlHelper.sqlcon();
string str = "select top " + AspNetPager1.PageSize + " * from 信息 where 信息类型='" + infor_type1 + "'and 信息号 not in (select top " + AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1) + " 信息号 from 信息 order by 信息号) order by 信息号";
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.sqlcon(), CommandType.Text, str); GridView1.DataSource = ds;
GridView1.DataBind();
mycon.Close();
}
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
Bind();
}
请问怎么回事,谢谢
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(Request["news_type"]!=null){
string infor_type = Request["news_type"].ToString();
SqlConnection mycon = SqlHelper.sqlcon();
mycon.Open();
string str = "select count(*) from 信息 where 信息类型='"+infor_type+"'";
SqlCommand mycom = new SqlCommand(str, mycon);
AspNetPager1.RecordCount = (int)mycom.ExecuteScalar();
AspNetPager1.CustomInfoHTML = "记录总数:<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoHTML += " 总页数:<font color='blue'><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
Bind();
}
}
}
private void Bind()
{
if (Request["news_type"] != null)
{
string infor_type1 = Request["news_type"].ToString();
SqlConnection mycon = SqlHelper.sqlcon();
string str = "select top " + AspNetPager1.PageSize + " * from 信息 where 信息类型='" + infor_type1 + "'and 信息号 not in (select top " + AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1) + " 信息号 from 信息 order by 信息号) order by 信息号";
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.sqlcon(), CommandType.Text, str); GridView1.DataSource = ds;
GridView1.DataBind();
mycon.Close();
}
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
Bind();
}
请问怎么回事,谢谢
protected void Page_Load(object sender, EventArgs e)
{
string con = ConfigurationSettings.AppSettings["mc"];
SqlConnection mycon = new SqlConnection(con);
mycon.Open();
string sql = "select count(*) from 信息";
SqlCommand mycom = new SqlCommand(sql, mycon);
AspNetPager1.RecordCount = (int)mycom.ExecuteScalar(); AspNetPager1.CustomInfoHTML = "记录总数:<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoHTML += " 总页数:<font color='blue'><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoHTML += " 当前页:<font color='red'><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
Bind();
}
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
Bind();
这个应该写在AspNetPager1_PageChanged中的,而不是AspNetPager1_PageChanging
protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{ this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
Bind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)与4楼说的
protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
并不符,强行改也会报错:
CS0234: 命名空间“Wuqi.Webdiyer”中不存在类型或命名空间名称“PageChangedEventArgs”(是缺少程序集引用吗?)
this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
Bind(); 放到pagechanged后,上面那一行去掉,只留下bind();
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
DataListDataBind();
AspNetPager1.CustomInfoHTML = "记录总数:<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoHTML += " 总页数:<font color='blue'><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
AspNetPager1.CustomInfoHTML += " 当前页:<font color='red'><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>"; }
把这些也写到changed事件那就正常显示了,还想请教一下各位,为什么我的跳转到指定页的那个textbox不能输入数值的
2.关键是你的Bind(),每次都是重新loading数据,自然每次都是第一页