分页的时候,删除把某个分页上的数据全部删除的时候就出现错误,该如何是好?
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
Source Error:
Line 153: view.Sort="Gid ASC";
Line 154: DataGrid1.DataSource=view;
Line 155: DataGrid1.DataBind();
Line 156: conn.Close();
Line 157:
Source File: d:\dotnet\test\wms_new\googsmanage.aspx.cs Line: 155
代码如果想看在下面:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 WMS_NEW
{
/// <summary>
/// Summary description for googsManage.
/// </summary>
public class googsManage : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WMS_NEW.DataSetQueryGoods dataSetQueryGoods1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Btn_Search;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.TextBox TextBox1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//this.sqlDataAdapter1.Fill(this.dataSetQueryGoods1);
BindGrid();
}
protected void OnNewPage(object sender, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dataSetQueryGoods1 = new WMS_NEW.DataSetQueryGoods();
((System.ComponentModel.ISupportInitialize)(this.dataSetQueryGoods1)).BeginInit();
this.Btn_Search.Click += new System.EventHandler(this.Btn_Search_Click);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Goods", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("GProvider1", "GProvider1"),
new System.Data.Common.DataColumnMapping("GProvider2", "GProvider2"),
new System.Data.Common.DataColumnMapping("GPrice", "GPrice"),
new System.Data.Common.DataColumnMapping("GName", "GName")})});
this.sqlDataAdapter1.RowUpdated += new System.Data.SqlClient.SqlRowUpdatedEventHandler(this.sqlDataAdapter1_RowUpdated);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT GID, GName, GPrice, GProvider1, GProvider2 FROM Goods";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=AARON;packet size=4096;integrated security=SSPI;data source=AARON;" +
"persist security info=False;initial catalog=WMS";
//
// dataSetQueryGoods1
//
this.dataSetQueryGoods1.DataSetName = "DataSetQueryGoods";
this.dataSetQueryGoods1.Locale = new System.Globalization.CultureInfo("zh-TW");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSetQueryGoods1)).EndInit();
}
#endregion
private void Btn_Search_Click(object sender, System.EventArgs e)
{
try
{
int varGid=Convert.ToInt32(TextBox1.Text.ToString());
Response.Redirect("goodsmodify.aspx?varGid="+varGid);
}
catch
{
Response.Write("沒有輸入或輸入錯誤!");
Response.End();
}
}
public void DataGrid_Delete (object sender, DataGridCommandEventArgs e)
{
//step1
string strconn=ConfigurationSettings.AppSettings["dsn"];//ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn=new SqlConnection(strconn);
//step2
SqlCommand cmd=new SqlCommand("goodsdelete",conn);
//step3: define cmd type:
cmd.CommandType =CommandType.StoredProcedure ;
//step4: define the parameter
cmd.Parameters .Add ("@GID",SqlDbType.Int );
cmd.Parameters ["@GID"].Value =Convert.ToInt32 (e.Item.Cells [1].Text.ToString ());
conn.Open();
//step5:execute
cmd.ExecuteNonQuery ();
DataGrid1.EditItemIndex =-1;
//finally :bind grid
BindGrid();
}
public void BindGrid()
{
string strconn=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn=new SqlConnection(strconn);
SqlDataAdapter adapter=new SqlDataAdapter("select * from goods ", conn);
DataSet ds=new DataSet();
adapter.Fill(ds);
DataView view=new DataView(ds.Tables[0]);
view.Sort="Gid ASC";
DataGrid1.DataSource=view;
DataGrid1.DataBind();
conn.Close();
}
private void sqlDataAdapter1_RowUpdated(object sender, System.Data.SqlClient.SqlRowUpdatedEventArgs e)
{
}
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
大家都是如何解决此类问题的?
Exception Details: System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
Source Error:
Line 153: view.Sort="Gid ASC";
Line 154: DataGrid1.DataSource=view;
Line 155: DataGrid1.DataBind();
Line 156: conn.Close();
Line 157:
Source File: d:\dotnet\test\wms_new\googsmanage.aspx.cs Line: 155
代码如果想看在下面:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 WMS_NEW
{
/// <summary>
/// Summary description for googsManage.
/// </summary>
public class googsManage : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WMS_NEW.DataSetQueryGoods dataSetQueryGoods1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Btn_Search;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.TextBox TextBox1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
//this.sqlDataAdapter1.Fill(this.dataSetQueryGoods1);
BindGrid();
}
protected void OnNewPage(object sender, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dataSetQueryGoods1 = new WMS_NEW.DataSetQueryGoods();
((System.ComponentModel.ISupportInitialize)(this.dataSetQueryGoods1)).BeginInit();
this.Btn_Search.Click += new System.EventHandler(this.Btn_Search_Click);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Goods", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("GProvider1", "GProvider1"),
new System.Data.Common.DataColumnMapping("GProvider2", "GProvider2"),
new System.Data.Common.DataColumnMapping("GPrice", "GPrice"),
new System.Data.Common.DataColumnMapping("GName", "GName")})});
this.sqlDataAdapter1.RowUpdated += new System.Data.SqlClient.SqlRowUpdatedEventHandler(this.sqlDataAdapter1_RowUpdated);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT GID, GName, GPrice, GProvider1, GProvider2 FROM Goods";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=AARON;packet size=4096;integrated security=SSPI;data source=AARON;" +
"persist security info=False;initial catalog=WMS";
//
// dataSetQueryGoods1
//
this.dataSetQueryGoods1.DataSetName = "DataSetQueryGoods";
this.dataSetQueryGoods1.Locale = new System.Globalization.CultureInfo("zh-TW");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSetQueryGoods1)).EndInit();
}
#endregion
private void Btn_Search_Click(object sender, System.EventArgs e)
{
try
{
int varGid=Convert.ToInt32(TextBox1.Text.ToString());
Response.Redirect("goodsmodify.aspx?varGid="+varGid);
}
catch
{
Response.Write("沒有輸入或輸入錯誤!");
Response.End();
}
}
public void DataGrid_Delete (object sender, DataGridCommandEventArgs e)
{
//step1
string strconn=ConfigurationSettings.AppSettings["dsn"];//ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn=new SqlConnection(strconn);
//step2
SqlCommand cmd=new SqlCommand("goodsdelete",conn);
//step3: define cmd type:
cmd.CommandType =CommandType.StoredProcedure ;
//step4: define the parameter
cmd.Parameters .Add ("@GID",SqlDbType.Int );
cmd.Parameters ["@GID"].Value =Convert.ToInt32 (e.Item.Cells [1].Text.ToString ());
conn.Open();
//step5:execute
cmd.ExecuteNonQuery ();
DataGrid1.EditItemIndex =-1;
//finally :bind grid
BindGrid();
}
public void BindGrid()
{
string strconn=ConfigurationSettings.AppSettings["dsn"];
SqlConnection conn=new SqlConnection(strconn);
SqlDataAdapter adapter=new SqlDataAdapter("select * from goods ", conn);
DataSet ds=new DataSet();
adapter.Fill(ds);
DataView view=new DataView(ds.Tables[0]);
view.Sort="Gid ASC";
DataGrid1.DataSource=view;
DataGrid1.DataBind();
conn.Close();
}
private void sqlDataAdapter1_RowUpdated(object sender, System.Data.SqlClient.SqlRowUpdatedEventArgs e)
{
}
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
大家都是如何解决此类问题的?
...全文
相关推荐
CI框架(ajax分页,全选,反选,不选,批量删除)完整代码详解
CodeIgniter 是一个小巧但功能强大的 PHP 框架。这篇文章主要介绍了CI框架(ajax分页,全选,反选,不选,批量删除)完整代码,需要的朋友可以参考下
ES深度分页.docx
es深度分页: 主要讨论了es的几种分页机制: 1、分页概述 2、浅分页 3、scroll深分页 4、search_after分页
java 分页、批量删除
包含了jsp的简单分页,有首页、尾页、上下页、设置页面数字等,有完整的注释、包、ppt等,mysql数据库的,对后台管理的删除有不错的参考价值,非常适合web初学者,改改就可以在多少场合运用。
Qt tableview实现翻页,翻页后选中,选中删除,全部删除,模糊搜索,跳转
Qt tableview实现翻页,翻页后选中,选中删除,全部删除,模糊搜索,跳转
asp+jquery ajax实例源码,添加,删除,修改,分页
基于jquery的ajax功能,对ASP网站的数据库进行无刷新操作,包括对数据库内容进行添加,删除,修改,分页


