分页的时候,删除把某个分页上的数据全部删除的时候就出现错误,该如何是好?

sylmoon sylmoon 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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)
{

}


}
}

大家都是如何解决此类问题的?
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
sylmoon
.NET社区 62,275 成员 668,968 内容