故障描述 下一页的时候 点第一下 行 点第二下,却还在第二页 即使还有第三页。这是前台页:(.aspx) int PageSize, RecordCount, PageCount, CurrentPage;
protected void Page_Load(object sender, EventArgs e)
{ PageSize = 20;
ListBind();
CurrentPage = 0; ViewState["PageIndex"] = 0;
//计算总共有多少记录
RecordCount = CalculateRecord();
lblRecordCount.Text = RecordCount.ToString(); //计算总共有多少页
PageCount = RecordCount / PageSize + 1;
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
//计算总共有多少条记录
public int CalculateRecord()
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open();
int intCount;
string strCount = "select count(*) from article where classid=1 ";
SqlCommand MyComm = new SqlCommand(strCount, conn);
intCount = Convert.ToInt32(MyComm.ExecuteScalar());
return intCount;
} ICollection CreateSource()
{ int StartIndex;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open(); //设定导入的起终地址
StartIndex = CurrentPage * PageSize;
string strSel = "select * from article where classid=1 order by articleid desc";
DataSet ds = new DataSet(); SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, conn);
MyAdapter.Fill(ds, StartIndex, PageSize, "article"); return ds.Tables["article"].DefaultView;
}
public void ListBind()
{
this.newsmore.DataSource = CreateSource();
this.newsmore.DataBind(); lbnNextPage.Enabled = false;
lbnPrevPage.Enabled = true;
if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
if (CurrentPage == 0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage + 1).ToString();
}
public void Page_onClick(Object sender, CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"]; string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch (cmd)
{
case "next":
if (CurrentPage < (PageCount - 1)) CurrentPage++;
break;
case "prev":
if (CurrentPage > 0) CurrentPage--;
break;
} ViewState["PageIndex"] = CurrentPage;
ListBind();
}这是后台程序页(.cs) int PageSize, RecordCount, PageCount, CurrentPage;
protected void Page_Load(object sender, EventArgs e)
{ PageSize = 20;
ListBind();
CurrentPage = 0; ViewState["PageIndex"] = 0;
//计算总共有多少记录
RecordCount = CalculateRecord();
lblRecordCount.Text = RecordCount.ToString(); //计算总共有多少页
PageCount = RecordCount / PageSize + 1;
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
//计算总共有多少条记录
public int CalculateRecord()
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open();
int intCount;
string strCount = "select count(*) from article where classid=1 ";
SqlCommand MyComm = new SqlCommand(strCount, conn);
intCount = Convert.ToInt32(MyComm.ExecuteScalar());
return intCount;
} ICollection CreateSource()
{ int StartIndex;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open(); //设定导入的起终地址
StartIndex = CurrentPage * PageSize;
string strSel = "select * from article where classid=1 order by articleid desc";
DataSet ds = new DataSet(); SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, conn);
MyAdapter.Fill(ds, StartIndex, PageSize, "article"); return ds.Tables["article"].DefaultView;
}
public void ListBind()
{
this.newsmore.DataSource = CreateSource();
this.newsmore.DataBind(); lbnNextPage.Enabled = false;
lbnPrevPage.Enabled = true;
if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
if (CurrentPage == 0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage + 1).ToString();
}
public void Page_onClick(Object sender, CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"]; string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch (cmd)
{
case "next":
if (CurrentPage < (PageCount - 1)) CurrentPage++;
break;
case "prev":
if (CurrentPage > 0) CurrentPage--;
break;
} ViewState["PageIndex"] = CurrentPage;
ListBind();
}序后台:
protected void Page_Load(object sender, EventArgs e)
{ PageSize = 20;
ListBind();
CurrentPage = 0; ViewState["PageIndex"] = 0;
//计算总共有多少记录
RecordCount = CalculateRecord();
lblRecordCount.Text = RecordCount.ToString(); //计算总共有多少页
PageCount = RecordCount / PageSize + 1;
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
//计算总共有多少条记录
public int CalculateRecord()
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open();
int intCount;
string strCount = "select count(*) from article where classid=1 ";
SqlCommand MyComm = new SqlCommand(strCount, conn);
intCount = Convert.ToInt32(MyComm.ExecuteScalar());
return intCount;
} ICollection CreateSource()
{ int StartIndex;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open(); //设定导入的起终地址
StartIndex = CurrentPage * PageSize;
string strSel = "select * from article where classid=1 order by articleid desc";
DataSet ds = new DataSet(); SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, conn);
MyAdapter.Fill(ds, StartIndex, PageSize, "article"); return ds.Tables["article"].DefaultView;
}
public void ListBind()
{
this.newsmore.DataSource = CreateSource();
this.newsmore.DataBind(); lbnNextPage.Enabled = false;
lbnPrevPage.Enabled = true;
if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
if (CurrentPage == 0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage + 1).ToString();
}
public void Page_onClick(Object sender, CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"]; string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch (cmd)
{
case "next":
if (CurrentPage < (PageCount - 1)) CurrentPage++;
break;
case "prev":
if (CurrentPage > 0) CurrentPage--;
break;
} ViewState["PageIndex"] = CurrentPage;
ListBind();
}这是后台程序页(.cs) int PageSize, RecordCount, PageCount, CurrentPage;
protected void Page_Load(object sender, EventArgs e)
{ PageSize = 20;
ListBind();
CurrentPage = 0; ViewState["PageIndex"] = 0;
//计算总共有多少记录
RecordCount = CalculateRecord();
lblRecordCount.Text = RecordCount.ToString(); //计算总共有多少页
PageCount = RecordCount / PageSize + 1;
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
//计算总共有多少条记录
public int CalculateRecord()
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open();
int intCount;
string strCount = "select count(*) from article where classid=1 ";
SqlCommand MyComm = new SqlCommand(strCount, conn);
intCount = Convert.ToInt32(MyComm.ExecuteScalar());
return intCount;
} ICollection CreateSource()
{ int StartIndex;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
conn.Open(); //设定导入的起终地址
StartIndex = CurrentPage * PageSize;
string strSel = "select * from article where classid=1 order by articleid desc";
DataSet ds = new DataSet(); SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, conn);
MyAdapter.Fill(ds, StartIndex, PageSize, "article"); return ds.Tables["article"].DefaultView;
}
public void ListBind()
{
this.newsmore.DataSource = CreateSource();
this.newsmore.DataBind(); lbnNextPage.Enabled = false;
lbnPrevPage.Enabled = true;
if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
if (CurrentPage == 0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage + 1).ToString();
}
public void Page_onClick(Object sender, CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"]; string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch (cmd)
{
case "next":
if (CurrentPage < (PageCount - 1)) CurrentPage++;
break;
case "prev":
if (CurrentPage > 0) CurrentPage--;
break;
} ViewState["PageIndex"] = CurrentPage;
ListBind();
}序后台:
解决方案 »
- 我这个存储过程哪里有问题哇? 返回不了数据挖
- 问题:如何通过字符段调用方法属性。
- mvc3 remote 验证成功如何返回信息还能通过ModelState.IsValid
- asp.net 使用模态窗体问题,高手们快来救命~~~
- 送分的!关于网站根目录
- 连接SQL SERVER 2005是说 管道的另一端上无任何进程。
- [新手]求建议
- 兄弟们帮我看看这个操作 为什么删除的时候 单数行提示“确定删除” 而2倍数的行就不提示 直接删除了 ?
- asp.net与oracle的问题
- 关于View State的行为的实验
- asp.net里面通过剪切板写入到word的问题!
- AJAX回调,pageload事件相关
{ PageSize = 20;
ListBind();
CurrentPage = 0; ViewState["PageIndex"] = 0;
//计算总共有多少记录
RecordCount = CalculateRecord();
lblRecordCount.Text = RecordCount.ToString(); //计算总共有多少页
PageCount = RecordCount / PageSize + 1;
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
没加 ispostback吧7楼: 我们至少把代码看完了 你没看代码 更没资格说啥