gridview删除行
//后台代码
protected void gv_categories_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string bookid=gv_categories.DataKeys[e.RowIndex].Value.ToString()
string sqlstr = "delete from Catagories where Bookid='" + bookid + "'";
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(sqlstr, conn);
cmd.ExecuteNonQuery();
bind();
}
我跟踪了一下;第一行就取不到值.bookid是空值
错误提示:索引超出范围。必须为非负值并小于集合大小。
参数名: index