我有一个网格视图,当我单击页面2时,给出的错误在我的sql命令处突出显示,它是:SqlCommand cmdShow = new SqlCommand("delete from Student where NRIC= '" + GridView1.DataKeys[0].Value + "'", conn);
并指出错误为:Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
指数超出范围。必须是非负的,并小于集合的大小
thsi是我的代码:
protected void GridView1_RowDeleted(Object sender, GridViewCommandEventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=MCDU\\SQLEXPRESS;Initial Catalog=n;Integrated Security=True");
conn.Open();
SqlCommand cmdShow = new SqlCommand("delete from Student where NRIC= '" + GridView1.DataKeys[0].Value + "'", conn);
cmdShow.ExecuteNonQuery();
conn.Close();
Response.Redirect("studentParticulars.aspx");
}
嗨,我有2个问题,您的网页2是否包含任何项目?这是否发生在页面2页面加载? –
我在我的数据库中有100个数据,我把它每个数据每页15个。但是一旦我点击第2页,它会提示我这个错误。是发生在第2页负载。 –
在这种情况下,你需要显示你的分页代码=) –