ASP.net报错提示:指定的参数已超出有效值的范围。参数名: index!
publicpartialclassAdmin_Seeadmin:System.Web.UI.Page{DBCC=newDB();publicvoidBin(){SqlC...
public partial class Admin_Seeadmin : System.Web.UI.Page
{
DB CC = new DB();
public void Bin()
{
SqlConnection myConn = CC.Getconnection();
myConn.Open();
string sqlStr = "select * from User_tb ";
SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
GridView1.DataSource = myDs;
GridView1.DataKeyNames = new string[] { "UserID" };
GridView1.DataBind();
myConn.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bin();
}
}
protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
CC.ExecSQL("delete from User_tb where UserID='" + this.GridView1.DataKeys[e.RowIndex].Value.ToString() + "'");
Bin();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}
}
添加这个事件就报错:GridView1_RowDataB 展开
{
DB CC = new DB();
public void Bin()
{
SqlConnection myConn = CC.Getconnection();
myConn.Open();
string sqlStr = "select * from User_tb ";
SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
GridView1.DataSource = myDs;
GridView1.DataKeyNames = new string[] { "UserID" };
GridView1.DataBind();
myConn.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bin();
}
}
protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
CC.ExecSQL("delete from User_tb where UserID='" + this.GridView1.DataKeys[e.RowIndex].Value.ToString() + "'");
Bin();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗?')");
}
}
}
添加这个事件就报错:GridView1_RowDataB 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询