//后台代码
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
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
那位兄弟与到过类似的问题.
<asp:GridView DataKeyNames="****" ...***是绑定数据时某一个字段名
现在搞出来了.