我准备每页显示25行,用的是access数据库
主要后台代码很简单,使这样的,
private void Page_Load(object sender, System.EventArgs e)
{
this.Button1.Click += new System.EventHandler(this.NavigateToPage);
this.Button2.Click += new System.EventHandler(this.NavigateToPage);
this.Button3.Click += new System.EventHandler(this.NavigateToPage);
this.Button4.Click += new System.EventHandler(this.NavigateToPage);
where = "Colid="+Request.QueryString["cid"];
le = Request.QueryString["le"];
if (!IsPostBack)
MyConnection("Select * from CommInfo where "+where+" ORDER BY PubTime DESC");
}
private void MyConnection(string MySql)
{
OleDbConnection conn = new OleDbConnection(Application["connstr"].ToString());
conn.Open(); OleDbCommand comm=new OleDbCommand(MySql,conn);
OleDbDataReader dr= comm.ExecuteReader();
dr.Close();
dr= comm.ExecuteReader();
if(dr.HasRows==true)
{
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
} dr.Close();
conn.Close();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
MyConnection("Select * from CommInfo where "+where+" ORDER BY PubTime DESC");
}
private void NavigateToPage(object sender, System.EventArgs e)
{
string PageInfo = ((Button)sender).CommandName;
switch (PageInfo)
{
case "首页":
DataGrid1.CurrentPageIndex = 0;
break;
case "上一页":
if (DataGrid1.CurrentPageIndex > 0)
DataGrid1.CurrentPageIndex -= 1;
break;
case "下一页":
if (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))
DataGrid1.CurrentPageIndex += 1;
break;
case "末页":
DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1);
break;
}
MyConnection("Select * from CommInfo where "+where+" ORDER BY PubTime DESC");
}可我运行时,显示出了前20条记录,但是点下一页刷新后还是这20条 请教高手帮我修改
主要后台代码很简单,使这样的,
private void Page_Load(object sender, System.EventArgs e)
{
this.Button1.Click += new System.EventHandler(this.NavigateToPage);
this.Button2.Click += new System.EventHandler(this.NavigateToPage);
this.Button3.Click += new System.EventHandler(this.NavigateToPage);
this.Button4.Click += new System.EventHandler(this.NavigateToPage);
where = "Colid="+Request.QueryString["cid"];
le = Request.QueryString["le"];
if (!IsPostBack)
MyConnection("Select * from CommInfo where "+where+" ORDER BY PubTime DESC");
}
private void MyConnection(string MySql)
{
OleDbConnection conn = new OleDbConnection(Application["connstr"].ToString());
conn.Open(); OleDbCommand comm=new OleDbCommand(MySql,conn);
OleDbDataReader dr= comm.ExecuteReader();
dr.Close();
dr= comm.ExecuteReader();
if(dr.HasRows==true)
{
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
} dr.Close();
conn.Close();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
MyConnection("Select * from CommInfo where "+where+" ORDER BY PubTime DESC");
}
private void NavigateToPage(object sender, System.EventArgs e)
{
string PageInfo = ((Button)sender).CommandName;
switch (PageInfo)
{
case "首页":
DataGrid1.CurrentPageIndex = 0;
break;
case "上一页":
if (DataGrid1.CurrentPageIndex > 0)
DataGrid1.CurrentPageIndex -= 1;
break;
case "下一页":
if (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))
DataGrid1.CurrentPageIndex += 1;
break;
case "末页":
DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1);
break;
}
MyConnection("Select * from CommInfo where "+where+" ORDER BY PubTime DESC");
}可我运行时,显示出了前20条记录,但是点下一页刷新后还是这20条 请教高手帮我修改
解决方案 »
- 在javaScript中得到 <asp:treeview>控件的值
- 求助:网站上传到服务器上之后出现BUG
- 文件上传
- |zyciis| 正则表达式如何匹配“任意字符” [.\n]*不行[\s\S]* 也不行
- 重装后VS2008安装错误Microsoft .net compact framwork 2.0 sp2 开始不能安装
- 哪位对测试有所了解
- 求教,关于是WebService问题
- 高分求解,关于复合控件校验!
- 我用asp.net新建了一个网站,运行后提示“成员名称不能与它们的封闭类型相同”的错误信息,如何解决?
- 我有个定义常量的文件,想许多.vb代码共享,该怎么办?
- 一个JS问题?
- 排版问题!
if (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))
DataGrid1.CurrentPageIndex += 1;
后面加上重新绑定数据源的代码:
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
我运行后显示的是25条 那我点下一页刷新后应该显示另外5条 可实际上还是显示的前25条,
我看了那个例子了 没什么不妥阿
在下一页加DataGrid1.DataBind();还是不行
就是DataGrid1.PageCount竟然是0 那就肯定不会执行DataGrid1.CurrentPageIndex += 1;那就永远显示第一页 这是那里出问题了阿 郁闷~~~~~~~~~~~~
再说我的datagrid怎么可能是零页呢
我还是不懂
到底要用datagrid的那一个属性来确定一页显示多少行那?
大哥门说明一下啊
小弟谢谢了!