索引
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Del")
{
int iIndex = Convert.ToInt32(e.CommandArgument);
string sUserID = GridView1.DataKeys[iIndex].Value.ToString();
SqlConnection con = new SqlConnection("server=.;database=Forum;uid=sa");
SqlCommand cmd = new SqlCommand("delete from tbUser where UserID=@UserID");
con.Open();
cmd.Parameters.AddWithValue("@UserID", sUserID);
Response.Write(string.Format("<script>alert('删除了{0}条记录')</script>", cmd.ExecuteNonQuery()));
bind();
}
}
报错:
索引超出范围。必须为非负值并小于集合大小。
参数名: index 请高手看下