//后台代码
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 

解决方案 »

  1.   

    我不知道为什么gv_categories.DataKeys[e.RowIndex].Value.ToString()老是取不到值;
    那位兄弟与到过类似的问题.
      

  2.   

    没有用过 gridview ,不知道觉得没有datagrid 好
      

  3.   

    在gridview的属性中要先指定DataKeys的值。
    <asp:GridView DataKeyNames="****" ...***是绑定数据时某一个字段名
      

  4.   

    谢谢楼上的兄弟,Iceguy(大侠龙卷风) 
    现在搞出来了.