在使用GridView的时候,删除事件中,写的如下代码,但编译时提示
System.Web.UI.WebControls.GridViewDeletedEventArgs”并不包含“RowIndex”的定义 //删除     protected void  GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            int affectRow = 0;
            String str = "server=localhost;database=DB;uid=sa;pwd=sa";
            SqlConnection sqlcon = new SqlConnection(str);
            String str1 = "update company set Status=-1 where Unid='" + GridView1.DataKeys[e.RowIndex].Value.ToString() +"'";
            SqlCommand cmd = new SqlCommand(str1,sqlcon); 
            try
            {
                sqlcon.Open();
                affectRow = cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                affectRow = 0;
                throw new ApplicationException(ex.Message);
            }
            finally
            {
                sqlcon.Close();       
            }
            if (affectRow > 0 )
            {
                BindSort();
            }
            else
            {
                Response.Redirect("www.sohu.com");
            }
                    }

解决方案 »

  1.   

    http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.gridviewdeletedeventargs_members(v=VS.80).aspx没有就直接找key吧
      

  2.   

    没这么用过,用ItemTemplter,加一个LinkButton,给属性CommandArgment赋值,用RowCommand事件来操作,这样比较好,灵活。不要用RowIndex.
      

  3.   

    GridView1_RowDeleted事件
    换成
    GridView1_RowDeleting事件
      

  4.   

    按照3楼说的,改了之后提示多了一个错误“ASP.info_cp_aspx”并不包含“GridView1_RowDeleted”的定义
    “System.Web.UI.WebControls.GridViewDeletedEventArgs”并不包含“RowIndex”的定义 还有1楼的直接找key是什么意思?
      

  5.   

    前台Gridview中的HTML代码 事件同样改
      

  6.   

    String str1 = "update company set Status=-1 where Unid='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";请问这句对吗? 如果执行更新语句的话,就把Status字段改成-1 ,直接把-1写在“” 里貌似不对吧?