Surya
Surya

Reputation: 188

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

I have a telerik RadDropDownList in my telerik RadGrid, whose editmode is FormTemplate. When I change RadDropDownList it work good in insert mode but in edit mode it got error.

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;
        }
    }

Upvotes: 0

Views: 890

Answers (1)

linden.phoenix
linden.phoenix

Reputation: 204

Since GridEditFormInsertItem is derived from GridEditFormItem, the following will work in both cases.

GridEditFormItem item = (GridEditFormItem)dropdownlist1.NamingContainer;

Upvotes: 1

Related Questions