This is a migrated thread and some comments may be shown as answers.

How to Find Control in EditFormSettings \ FormTemplate

4 Answers 361 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 07 May 2009, 06:55 PM
I have a combo box and a button inside of a EditFormSettings \ FormTemplate.  In the Items_command event of the grid I trap the buitton click event and I'm tryiong to enable or disable it.

Here is the page code

<

 

telerik:RadGrid ID="RadGrid1" runat="server">

 

 

<HeaderContextMenu EnableTheming="True">

 

 

<CollapseAnimation Type="OutQuint" Duration="200">

 

 

</CollapseAnimation>

 

 

</HeaderContextMenu>

 

 

<MasterTableView CommandItemDisplay="Top" DataKeyNames="Contact_ID" Width="100%"

 

 

ExpandCollapseColumn-Display="true" HierarchyDefaultExpanded="false"

 

 

EditMode="EditForms" AllowPaging="True" PageSize="5">

 

 

<ItemTemplate>

 

 

<span lang="en-us">ITEM TEMPLATE</span>

 

 

</ItemTemplate>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</ExpandCollapseColumn>

 

 

<EditFormSettings EditFormType="Template">

 

 

<FormTemplate>

 

 

<asp:DropDownList ID="cboCountry" runat="server" Enabled="false">

 

 

</asp:DropDownList>

 

 

<asp:Button runat="server" ID="butCountry" text="change" CausesValidation="False"

 

 

CommandName="ChangeCountry" />

 

 

<br />

 

 

<br />

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

 

</MasterTableView>

 

 

<FilterMenu EnableTheming="True">

 

 

<CollapseAnimation Type="OutQuint" Duration="200">

 

 

</CollapseAnimation>

 

 

</FilterMenu>

 

 

</telerik:RadGrid>

 



and here is the Item_command event in the code behind


 

Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand

 

 


Dim
strCommand As String

 

strCommand = e.CommandName.ToUpper


Select

 

Case strCommand

 

 

    Case Is = "CHANGECOUNTRY"

 

 

       Dim editItem As GridDataItem = CType(e.Item, GridDataItem)

 

       Dim

 

ContactCombo As DropDownList = CType(editItem.FindControl("cboCountry"), DropDownList)

 

        ContactCombo.Enable = "True"

 

    End Select

 

 

End Sub

 


Why is it that I can't get a handle to the combo box ?

Any help would be great !

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 May 2009, 04:36 AM
Hello Ron,

You would have to cast the controls in the EditForm as EditFormItem/EditableItem and not as GridDataItem:
vb:
Private Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand   
 Dim strCommand As String strCommand = e.CommandName.ToUpper   
  Select Case strCommand  
    Case Is = "CHANGECOUNTRY"   
         Dim editItem As GridEditFormItem = CType(e.Item, GridEditFormItem)   
         Dim ContactCombo As DropDownList = CType(editItem.FindControl("cboCountry"), DropDownList)  
         ContactCombo.Enable = "True"  
     End Select   
End Sub  
 

Thanks
Princy.
0
Ron
Top achievements
Rank 1
answered on 11 May 2009, 02:57 PM
Princy

Worked perfectly. You are truly of royalty !

Ron
0
ram sagar reddy
Top achievements
Rank 1
answered on 18 Aug 2015, 03:25 PM
An exception of type 'System.InvalidCastException' occurred in DCSE.iAPECS.Web.UI.dll but was not handled in user code

Additional information: Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridEditFormItem'.
0
Viktor Tachev
Telerik team
answered on 20 Aug 2015, 01:43 PM
Hi Ram,

The error you are seeing is caused because you are trying to case a GridCommandItem as GridEditFormItem.

In order to resolve the issue you can add a check for the type of the item:

Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If TypeOf e.Item Is GridEditFormItem Then
 
        Dim editFormItem As GridEditFormItem = TryCast(e.Item, GridEditFormItem)
    End If
End Sub



Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Ron
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ron
Top achievements
Rank 1
ram sagar reddy
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or