“索引超出范围。必须为非负值并小于集合大小。参数名: index ”怎么解决?

void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)  

      {            int muckid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);           

int delRowNum = nu.DeleteMuck(muckid);//删除的行数据;      

      if (delRowNum > 0)          

  {                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "script", "alert('删除成功!');", true);             }          

  else        

    {                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "script", "alert('删除失败!');", true);             }          

   BindData();   

      }

 解决方法:    GridView1.DataKeyNames = new string[] { "tea_muckID" };//主键

你可能感兴趣的:(“索引超出范围。必须为非负值并小于集合大小。参数名: index ”怎么解决?)