Search code examples
c#asp.netgridviewweb-controls

Adding an EditIndex to a Panel in Gridview Edit: can't set because the property doesn't already exist


Error:

'System.Web.UI.WebControls.Panel' does not contain a definition for 'EditIndex' and no extension method 'EditIndex' accepting a first argument of type 'System.Web.UI.WebControls.Panel' could be found (are you missing a using directive or an assembly reference?)

My code:

protected void OnRowEditing(object sender, GridViewEditEventArgs e)
    {
        pnlGrid.EditIndex = e.NewEditIndex;
        this.DataBind();
    }

Solution

  • I think you have put a Panel reference instead of a GridView reference.

    [edit]

    Example:

    <asp:GridView id="theGrid" runat="server" Visible="true" OnRowEditing="OnRowEditing" OnRowDeleting ="delete" OnRowUpdating = "Update" />
    

    and OnRowEditing to access the grid:

    theGrid.EditIndex = e.NewEditIndex;
    

    So, you are accessing a GridView, not a Panel which is a "static" control.