protected void roleGrid_Update(object sender, GridViewUpdatedEventArgs e)
    {
       
        GridViewRow myrow = GridView1.Rows;
        string id = ((TextBox)myrow.Cells[1].Controls[0]).Text;
        string name = ((TextBox)myrow.Cells[2].Controls[0]).Text;
               
        string myConn = ConfigurationManager.AppSettings["connString1"];
        
        SqlConnection conn = new SqlConnection(myConn);
        conn.Open();
        string sql = "update role set roleId='"+id+"',roleName='"+name+"' ";
        SqlCommand cmd = new SqlCommand(sql,conn); 
        try
        {
            cmd.ExecuteNonQuery();
            GridView1.EditIndex = -1;
            conn.Close();
            BindGrid();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
            }////////////////////////////////////////////////////////////////
还有我的GridViewUpdatedEventArgs 类中也没有EditIndex属性。
这是怎么回事啊?在线等!

解决方案 »

  1.   

    1.<asp:GridView ID="roleGrid" OnRowUpdating="roleGrid_Update" ...2.
    GridViewUpdateEventArgs本来就没有EditIndex属性~
      

  2.   

    更新gridview还用写代码?上边这样使用sqldatasource就ok了
      

  3.   

    应该写在updating 事件里
    protected void roleGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }试试
      

  4.   

    GridViewRow myrow = GridView1.Rows;
    上面那行也有错误。
    提示GridView1无法隐式转换类型。