How to Find Control in EditFormSettings \ FormTemplate

5 posts, 1 answers
  1. Ron
    Ron  avatar
    2 posts
    Member since:
    Feb 2009

    Posted 07 May 2009 Link to this post

    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 !
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ron
    Ron  avatar
    2 posts
    Member since:
    Feb 2009

    Posted 11 May 2009 Link to this post

    Princy

    Worked perfectly. You are truly of royalty !

    Ron
  5. ram sagar reddy
    ram sagar reddy avatar
    1 posts
    Member since:
    Aug 2015

    Posted 18 Aug 2015 in reply to Princy Link to this post

    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'.
  6. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 20 Aug 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017