if (!IsPostBack)
{
SqlConnection nwindConn = new SqlConnection("server=server;uid=;pwd=;Database=TNet");
nwindConn.Open(); SqlDataAdapter myDa = new SqlDataAdapter();
SqlCommand sqstr;
DataSet ds = new DataSet(); sqstr = new SqlCommand("select * from GjGl", nwindConn);
myDa.SelectCommand = sqstr;
myDa.Fill(ds, "稿件");
DataGrid1.Attributes.Add("ID", "gray");
DataGrid1.Attributes.Add("ZCaption", "#ffffcc");
DataGrid1.Attributes.Add("Author", "#BEC5DE"); this.DataGrid1.DataSource = ds;
this.DataGrid1.DataBind();
ds.Dispose();
myDa.Dispose();
myDa.Dispose();
nwindConn.Close();
nwindConn.Dispose();
}
这是数据的绑定,在属性中设置了Allowpaging=true,但是每次点击下一页就没有反应,而且在下面显示:javascript:_doPostBack('DataGrid1$_ct19$_ctl1',")。
请问应该如何解决?谢谢!
{
SqlConnection nwindConn = new SqlConnection("server=server;uid=;pwd=;Database=TNet");
nwindConn.Open(); SqlDataAdapter myDa = new SqlDataAdapter();
SqlCommand sqstr;
DataSet ds = new DataSet(); sqstr = new SqlCommand("select * from GjGl", nwindConn);
myDa.SelectCommand = sqstr;
myDa.Fill(ds, "稿件");
DataGrid1.Attributes.Add("ID", "gray");
DataGrid1.Attributes.Add("ZCaption", "#ffffcc");
DataGrid1.Attributes.Add("Author", "#BEC5DE"); this.DataGrid1.DataSource = ds;
this.DataGrid1.DataBind();
ds.Dispose();
myDa.Dispose();
myDa.Dispose();
nwindConn.Close();
nwindConn.Dispose();
}
这是数据的绑定,在属性中设置了Allowpaging=true,但是每次点击下一页就没有反应,而且在下面显示:javascript:_doPostBack('DataGrid1$_ct19$_ctl1',")。
请问应该如何解决?谢谢!
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);}
#endregion在CS中的上面内设那this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
或者在页面上直接设
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataBindToDG();//重新绑定数据
}
{
[你控件名称].CurrentPageIndex = e.NewPageIndex;
然后从新绑定:[你控件名称].DataBind();
}
我用了
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();
}
但是一点下一页,怎么什么都没有了?
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;他们要写在ing事件不是ed事件
GridView吧
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;}
用了这个事件后,点击下一页,还是空白,是不是还有什么地方不对?