我是Asp.net的新手。我希望在单击网格上的链接按钮后删除gridview行。我试图获取我使用datakeys单击的gridview行的主键,然后将其传递给Delete存储过程。但是我得到了索引超出范围的例外。请帮帮我怎么办? 这是我的代码
GridView grid=(GridView)sender;
LinkButton lnkbtndelete = (LinkButton)e.CommandSource;
GridViewRow grdvwrw = (GridViewRow)lnkbtndelete.NamingContainer;
int pkey = Convert.ToInt32(grid.DataKeys[grdvwrw.RowIndex].Value.ToString());
SqlCommand cmd3 = new SqlCommand("USP_DELETE_NOTICE", con2);
cmd3.CommandType = CommandType.StoredProcedure;
cmd3.Parameters.AddWithValue("@NOTICEID", pkey);
int rowsdeleted = cmd3.ExecuteNonQuery();`enter code here`