Find Control On Insert Item

2 posts, 0 answers
  1. Trevor
    Trevor avatar
    22 posts
    Member since:
    Jul 2010

    Posted 30 Aug 2017 Link to this post

    I need to get a reference to a combo box on that is in an edittemplatecolumn. I only need the reference on post back after the first combo box has an item selected.

    As you can see below I have a very simple grid for testing purposes. I basically just want to select cmboCondition and have it auto post back. On item index changed, I want to populate cmboCondition2 however I can't get a reference to cmboCondition2.

    <telerik:RadGrid ID="gridConditions" EnableTheming="false" runat="server" AllowPaging="false" AllowSorting="false" AllowFilteringByColumn="false" PageSize="1000" AutoGenerateColumns="false">
        <GroupingSettings CaseSensitive="false" />
        <ClientSettings>
            <Scrolling AllowScroll="False" />
            <Selecting AllowRowSelect="true" />
        </ClientSettings>
        <MasterTableView CommandItemDisplay="Top" AllowNaturalSort="false" NoMasterRecordsText="There are no conditions. Please add one to the rule." ShowHeader="false">
            <CommandItemTemplate>
                <div style="padding-left:8px; padding-right:8px; padding-top:6px; padding-bottom:6px;">
                    <table width="100%">
                        <tr>
                            <td runat="server" Visible='<%# Not gridConditions.MasterTableView.IsItemInserted%>'>
                                <asp:LinkButton ID="btnAddCondition" runat="server" ToolTip="Add Condition" CommandName="InitInsert" Visible='<%# Not gridConditions.MasterTableView.IsItemInserted%>'><asp:Image ID="imgAddCondition" runat="server" ImageUrl="~/images/add_button.gif"/>Add</asp:LinkButton>   
                                <asp:LinkButton ID="btnDeleteCondition" runat="server" ToolTip="Delete Condition" OnClientClick = " return confirm('Are you sure you want to delete the selected condition?');" CommandName="DeleteSelected" Visible='<%# Not gridConditions.MasterTableView.IsItemInserted%>'><asp:Image ID="Image1" runat="server" ImageUrl="~/images/delete_button.gif"/>Delete</asp:LinkButton>
                            </td>
                            <td runat="server" Visible='<%# gridConditions.MasterTableView.IsItemInserted%>'>
                            <asp:LinkButton ID="btnInsertCondition" runat="server" ToolTip="Confirm Add" CommandName="PerformInsert" Visible='<%# gridConditions.MasterTableView.IsItemInserted%>'><asp:Image ID="imgInsertCondition" runat="server" ImageUrl="~/images/updaterecord_button.gif"/>Confirm Add</asp:LinkButton>   
                                <asp:LinkButton ID="btnCancelCondition" runat="server" ToolTip="Cancel Add" CommandName="CancelAll" Visible='<%# gridConditions.EditIndexes.Count > 0 or gridConditions.MasterTableView.IsItemInserted %>'><asp:Image ID="imgCancelCondition" runat="server" ImageUrl="~/images/cancel_button.gif"/>Cancel Add</asp:LinkButton>
                            </td>
                        </tr>
                    </table>
                </div>
            </CommandItemTemplate>
            <Columns>
                <telerik:GridTemplateColumn UniqueName="Condition" HeaderText="" AllowFiltering="false" ItemStyle-Wrap="false">
                    <ItemTemplate>
                        <table>
                            <tr>
                                <td>
                                    <asp:Label runat="server" ID="lblCondition" Text="" />
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblCondition2" Text="" />
                                </td>
                                <td>
                                    <asp:Label runat="server" ID="lblValue" Text="" />
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <table>
                            <tr>
                                <td>
                                    <telerik:RadComboBox runat="server" ID="cmboCondition" AutoPostBack="true" OnSelectedIndexChanged="cmboCondition_OnSelectedIndexChanged">
                                        <Items>
                                            <telerik:RadComboBoxItem Text="Select One" Value="0" />
                                            <telerik:RadComboBoxItem Text="The sender ..." Value="1" />
                                            <telerik:RadComboBoxItem Text="The recipient ..." Value="2" />
                                            <telerik:RadComboBoxItem Text="The subject or body ..." Value="3" />
                                            <telerik:RadComboBoxItem Text="Any attachment ..." Value="4" />
                                            <telerik:RadComboBoxItem Text="Any recipient ..." Value="5" />
                                            <telerik:RadComboBoxItem Text="A message header ..." Value="6" />
                                        </Items>
                                    </telerik:RadComboBox>
                                </td>
                                <td>
                                    <telerik:RadComboBox runat="server" ID="cmboCondition2"/>
                                </td>
                                <td>
                                    This is where the value popup goes
                                </td>
                            </tr>
                        </table>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    Private Sub PopulateConditions(ByVal clientID As String)
            Dim cmboCondition2 As RadComboBox = gridConditions.MasterTableView.FindControl(clientID)
     
            For Each item As GridDataItem In gridConditions.EditItems
                cmboCondition2 = CType(item("Condition").FindControl("cmboCondition2"), RadComboBox)
            Next
     
            If Not cmboCondition2 Is Nothing Then
                Dim prmParentID As New SqlParameter("@ParentID", cmboCondition2.SelectedValue)
                Dim arrParameters() As SqlParameter = {prmParentID}
     
                Dim dsValues As DataSet = mySQLFunctions.SQLStoredProc("sp_selectDLPConditionsByParentID", arrParameters)
     
                If dsValues.Tables.Count > 0 Then
                    cmboCondition2.DataSource = dsValues.Tables(0)
                    cmboCondition2.DataTextField = "Text"
                    cmboCondition2.DataValueField = "Value"
                    cmboCondition2.DataBind()
                End If
            End If
        End Sub
     
        Protected Sub gridConditions_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gridConditions.NeedDataSource
            gridConditions.DataSource = New Datatable()
        End Sub
     
        Protected Sub gridConditions_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)
            If TypeOf e.Item Is GridCommandItem Then
     
                Dim commandItem As GridCommandItem = CType(e.Item, GridCommandItem)
                Dim insertButton As LinkButton = CType(commandItem.FindControl("PerformInsertButton"), LinkButton)
                Dim cancelButton As LinkButton = CType(commandItem.FindControl("CancelButton"), LinkButton)
     
                insertButton.Visible = False
                cancelButton.Visible = False
            End If
        End Sub
     
        Protected Sub cmboCondition_OnSelectedIndexChanged(ByVal sender As RadComboBox, ByVal e As EventArgs)
            PopulateConditions(sender.ClientID & "2")
        End Sub

     

  2. Trevor
    Trevor avatar
    22 posts
    Member since:
    Jul 2010

    Posted 07 Sep 2017 in reply to Trevor Link to this post

    I have found the anwwer that I needed for this in case anyone needed it.

    Dim item As GridEditFormInsertItem = CType(gridConditions.MasterTableView.GetItems(GridItemType.EditFormItem)(0), GridEditFormInsertItem)
     
            cmboCondition = CType(item("Condition").FindControl("cmboCondition"), RadComboBox)

     

    However, I now need to do the same exact thing client side. I need javascript that allows me to access the row that is going to be inserted. This is what I have. I also tried get_insertitem() with no luck.

    function OnClientClose(oWnd, args) {
            //get the transferred arguments
            var arg = args.get_argument();
     
            if (arg) {
                var EntityKeyName = $find("<%= gridConditions.ClientID%>").get_masterTableView().get_dataItems()[0].findControl("lblTest");
                var editForm = $find("<%= gridConditions.ClientID%>").get_masterTableView().get_editItems()[0];
                alert(editForm);
            }
        }

     

Back to Top