datagrid分页问题

sjzwinfor 2003-11-27 06:54:21
大家帮我看看这个代码,为什么分页后点下一页没有反应
====================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data .OleDb ;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;


namespace wlkc
{

/// <summary>
/// WebForm3 的摘要说明。
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.DataSet ds;

public OleDbDataAdapter dp;
public OleDbConnection myConnection;

private void Page_Load(object sender, System.EventArgs e)
{

if(!Page.IsPostBack)
{
string connstr = ConfigurationSettings.AppSettings ["wlkcdb"].ToString ();
myConnection = new OleDbConnection(ConfigurationSettings.AppSettings ["wlkcdb"].ToString ());

string sqlstr="select * from WLKC where KCLB='ZBZS'";


dp=new OleDbDataAdapter(sqlstr,myConnection) ;

bind ();
}
}



#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ds = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.ds)).BeginInit();
//
// ds
//
this.ds.DataSetName = "NewDataSet";
this.ds.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.ds)).EndInit();

}
#endregion

//==========定义绑定方法bind()
public void bind()
{

try
{
this.myConnection.Open();
dp.Fill(ds,"wlkc");//传递给“网络课程”表
//保存为Session
this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();
this.myConnection.Close();

}
catch
{
Response.Redirect ("database-error.htm");
}

}

private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
bind();
}






}
}
...全文
53 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjzwinfor 2003-11-27
  • 打赏
  • 举报
回复
qiuji(忆秋季),thanks
sjzwinfor 2003-11-27
  • 打赏
  • 举报
回复
freexin(小昕)你好,加入后,点下一页会跳到database-error.htm
BenZ004 2003-11-27
  • 打赏
  • 举报
回复
恩,在你的region设计器代码里好象没有看到分页事件的注册啊.
在下面的事件里加上:---------this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
--------------------------------------------------------------------------
private void InitializeComponent()
{
this.ds = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.ds)).BeginInit();
//
// ds
//
this.ds.DataSetName = "NewDataSet";
this.ds.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.ds)).EndInit();

}

freexin 2003-11-27
  • 打赏
  • 举报
回复
在private void InitializeComponent()里
加入this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
qiuji 2003-11-27
  • 打赏
  • 举报
回复
这样试试:
Page_Load事件这样写:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
bind ();
}
}

然后,bind()这样写:
public void bind()
{

try
{
string connstr = ConfigurationSettings.AppSettings ["wlkcdb"].ToString ();
myConnection = new OleDbConnection(ConfigurationSettings.AppSettings ["wlkcdb"].ToString ());

string sqlstr="select * from WLKC where KCLB='ZBZS'";

dp=new OleDbDataAdapter(sqlstr,myConnection) ;
this.myConnection.Open();
dp.Fill(ds,"wlkc");//传递给“网络课程”表
this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();
this.myConnection.Close();

}
catch
{
Response.Redirect ("database-error.htm");
}

}

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧