从 DropDownList selectedindexchanged 访问插入和编辑事件中的 RadGrid 编辑表单模板项

Access RadGrid EditForm template items in Insert & Edit events from RadDropDownList selectedindexchanged

我的telerik RadGrid中有一个telerik RadDropDownList,它的editmode是FormTemplate。当我更改 RadDropDownList 时,它在插入模式下运行良好,但在编辑模式下出现错误。

InvalidCastException = "Unable to cast object of type 'Telerik.Web.UI.GridEditFormItem' to type 'Telerik.Web.UI.GridEditFormInsertItem'."

protected void TransactionTypeTextBox_SelectedIndexChanged(object sender, DropDownListEventArgs e)
    {
        RadDropDownList dropdownlist1 = (RadDropDownList)sender;
        GridEditFormInsertItem item = (GridEditFormInsertItem)dropdownlist1.NamingContainer;
        Panel Panel1 = (Panel)item.FindControl("Panel1");
        if (dropdownlist1.SelectedItem.Text == "Cheque")
        {
            Panel1.Visible = true;
        }
        else if (dropdownlist1.SelectedItem.Text == "Cash")
        {
            Panel1.Visible = false;
        }
    }

由于 GridEditFormInsertItem 是从 GridEditFormItem 派生的,因此以下内容适用于这两种情况。

GridEditFormItem item = (GridEditFormItem)dropdownlist1.NamingContainer;