在 Gridview 编辑中将 EditIndex 添加到面板:无法设置,因为 属性 尚不存在

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

错误:

'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?)

我的代码:

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

我认为您放置了面板参考而不是 GridView 参考。

[编辑]

示例:

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

OnRowEditing访问网格:

theGrid.EditIndex = e.NewEditIndex;

因此,您访问的是 GridView,而不是作为 "static" 控件的面板。