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

Cascading RadComboBoxes inside RadGrid

6 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dwight
Top achievements
Rank 1
Dwight asked on 23 May 2012, 10:28 AM

Hi

I have tried for hours and read a thousand posts on this but cant master it

I have cascading RadComboBox controls inside a RadGrid and found the code below in a forum that works perfectly

The problem is that when I place the RadGrid inside a FormView control it no longer works, I get an error that says Cannot find a cell bound to column name 'HSG'

If anyone could tell me how to reference the controls inside of a formview I would be eternally grateful :)

Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)

        Dim rdcbx As RadComboBox = CType(sender, RadComboBox)
        Dim editedItem As GridEditableItem = CType(rdcbx.NamingContainer, GridEditableItem)

        Dim RadComboBox1 As RadComboBox = CType(CType(editedItem, GridEditableItem) ("HSG").FindControl("RadComboBox1"), RadComboBox)
Dim RadComboBox2 As RadComboBox = CType(editedItem("HSG").FindControl("RadComboBox2"), RadComboBox)

        RadComboBox2.Items.Clear()
        RadComboBox2.Items.Insert(0, New RadComboBoxItem("", String.Empty))
        Me.ObjectDataSource1.SelectParameters("KeyID").DefaultValue = RadComboBox1.SelectedValue.ToString
        RadComboBox2.DataBind()

    End Sub

6 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 May 2012, 10:37 AM
Hello,

Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
    Dim rdcbx As RadComboBox = DirectCast(sender, RadComboBox)
    Dim editedItem As GridEditableItem = DirectCast(rdcbx.NamingContainer, GridEditableItem)
 
    Dim RadComboBox1 As RadComboBox = DirectCast(DirectCast(editedItem.FindControl("RadComboBox1"), GridEditableItem), RadComboBox)
    Dim RadComboBox2 As RadComboBox = DirectCast(editedItem.FindControl("RadComboBox2"), RadComboBox)
 
    RadComboBox2.Items.Clear()
    RadComboBox2.Items.Insert(0, New RadComboBoxItem("", String.Empty))
    Me.ObjectDataSource1.SelectParameters("KeyID").DefaultValue = RadComboBox1.SelectedValue.ToString
    RadComboBox2.DataBind()
 
End Sub


note : if you used form for editing then replace "GridEditableItem" with "GridEditFormItem".

Thanks,
Jayesh Goyani
0
Dwight
Top achievements
Rank 1
answered on 23 May 2012, 11:25 AM

Hi Jayesh and thx so much but unfortunately I have the same error

When attempting to reference the RadGrid in edit mode it is inside the FormView which is also in edit mode

I tried this code and it still has the error Cannot find a cell bound to column name 'HSG' 

Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
    Dim rdcbx As RadComboBox = DirectCast(sender, RadComboBox)
    Dim GridEditFormItem As GridEditFormItem DirectCast(rdcbx.NamingContainer, GridEditableItem)
 
    Dim RadComboBox1 As RadComboBox = DirectCast(DirectCast(GridEditFormItem.FindControl("RadComboBox1"), GridEditableItem), RadComboBox)
    Dim RadComboBox2 As RadComboBox = DirectCast(editedItem.FindControl("RadComboBox2"), RadComboBox)
 
    RadComboBox2.Items.Clear()
    RadComboBox2.Items.Insert(0, New RadComboBoxItem(""String.Empty))
    Me.ObjectDataSource1.SelectParameters("KeyID").DefaultValue = RadComboBox1.SelectedValue.ToString
    RadComboBox2.DataBind()
 
End Sub

I dont know how to reference the code while the RadGrid is nested inside a FormView, although that code works great if it is outside of the FormView

Any ideas?



0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 May 2012, 11:57 AM
Hello,

can you please provide grid  (UI) code?

Thanks,
Jayesh Goyani
0
Dwight
Top achievements
Rank 1
answered on 23 May 2012, 01:10 PM

Hi, Im not quite sure what you mean by UI code but here is the markup for the RadGrid - pls if you meant something else then let me know

You will notice that the RadComboBoxes are named differently but I tried to simplify it when I asked the question :)

Thank you so so much for taking the time to help me, that is so nice

<telerik:RadGrid ID="DeptsRadGrid" runat="server" 
                            AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" AllowSorting="True" 
                            AutoGenerateColumns="False" CellSpacing="0" DataSourceID="Depts" 
                            GridLines="None" Width="500px" onprerender="DeptsRadGrid_PreRender">
                            <mastertableview allowsorting="False" commanditemdisplay="top" datakeynames="ID" 
                                datasourceid="Depts">
                                <CommandItemSettings ExportToPdfText="Export to PDF" />
                                <rowindicatorcolumn filtercontrolalttext="Filter RowIndicator column">
                                    <HeaderStyle Width="20px" />
                                </rowindicatorcolumn>
                                <expandcollapsecolumn filtercontrolalttext="Filter ExpandColumn column">
                                    <HeaderStyle Width="20px" />
                                </expandcollapsecolumn>
                                <Columns>
                                    <telerik:GridTemplateColumn DataField="Level1Account" 
                                        FilterControlAltText="Filter Level1Account column" HeaderText="HSG" 
                                        SortExpression="Level1Account" UniqueName="Level1Account">
                                        <EditItemTemplate>
                                            <span style="font-size: 10pt; font-family: Arial">
                                            <span style="font-family: Arial">
                                            <telerik:RadComboBox ID="Level2RadComboBox" Runat="server" 
                                                AppendDataBoundItems="True" AutoPostBack="True" DataSourceID="Level1Account" 
                                                DataTextField="Account" DataValueField="ID" 
                                                onselectedindexchanged="Level2RadComboBox_SelectedIndexChanged" 
                                                Width="300px">
                                            </telerik:RadComboBox>
                                            <asp:ObjectDataSource ID="Level1Account" runat="server" DeleteMethod="Delete" 
                                                InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 
                                                SelectMethod="GetDataByAccountID" 
                                                TypeName="AccountsDataSetTableAdapters.AccountL2TableAdapter" 
                                                UpdateMethod="Update">
                                                <DeleteParameters>
                                                    <asp:Parameter Name="Original_ID" Type="Int32" />
                                                </DeleteParameters>
                                                <UpdateParameters>
                                                    <asp:Parameter Name="AccountID" Type="String" />
                                                    <asp:Parameter Name="Account" Type="String" />
                                                    <asp:Parameter Name="PassWord" Type="String" />
                                                    <asp:Parameter Name="Mail" Type="String" />
                                                    <asp:Parameter Name="Original_ID" Type="Int32" />
                                                </UpdateParameters>
                                                <SelectParameters>
                                                    <asp:CookieParameter CookieName="Account" Name="AccountID" Type="String" />
                                                </SelectParameters>
                                                <InsertParameters>
                                                    <asp:Parameter Name="AccountID" Type="String" />
                                                    <asp:Parameter Name="Account" Type="String" />
                                                    <asp:Parameter Name="PassWord" Type="String" />
                                                    <asp:Parameter Name="Mail" Type="String" />
                                                </InsertParameters>
                                            </asp:ObjectDataSource>
                                            <telerik:RadComboBox ID="Level3RadComboBox" Runat="server" 
                                                AppendDataBoundItems="True" datasourceid="Level2Account" 
                                                DataTextField="Account" DataValueField="Account" 
                                                onselectedindexchanged="Level3RadComboBox_SelectedIndexChanged" Width="300px">
                                            </telerik:RadComboBox>
                                            <asp:ObjectDataSource ID="Level2Account" runat="server" DeleteMethod="Delete" 
                                                OldValuesParameterFormatString="original_{0}" 
                                                SelectMethod="GetDataByAccountL2ID" 
                                                TypeName="AccountsDataSetTableAdapters.AccountL3TableAdapter">
                                                <DeleteParameters>
                                                    <asp:Parameter Name="Original_ID" Type="Int32" />
                                                </DeleteParameters>
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="Level2RadComboBox" Name="AccountL2ID" 
                                                        PropertyName="SelectedValue" Type="Int32" />
                                                </SelectParameters>
                                            </asp:ObjectDataSource>
                                            <asp:HiddenField ID="Level3HiddenField" runat="server" 
                                                Value='<%# Bind("Level2Account") %>' />
                                            <br />
                                            <br />
                                            </span></span>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                            <span style="font-size: 10pt; font-family: Arial">
                                            <span style="font-family: Arial">
                                            <telerik:RadComboBox ID="Level2RadComboBox" Runat="server" 
                                                AppendDataBoundItems="True" DataSourceID="Level1Account" 
                                                DataTextField="Account" DataValueField="ID" 
                                                onselectedindexchanged="Level2RadComboBox_SelectedIndexChanged" 
                                                Width="300px" AutoPostBack="True">
                                            </telerik:RadComboBox>
                                            <asp:ObjectDataSource ID="Level1Account" runat="server" DeleteMethod="Delete" 
                                                InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 
                                                SelectMethod="GetDataByAccountID" 
                                                TypeName="AccountsDataSetTableAdapters.AccountL2TableAdapter" 
                                                UpdateMethod="Update">
                                                <DeleteParameters>
                                                    <asp:Parameter Name="Original_ID" Type="Int32" />
                                                </DeleteParameters>
                                                <UpdateParameters>
                                                    <asp:Parameter Name="AccountID" Type="String" />
                                                    <asp:Parameter Name="Account" Type="String" />
                                                    <asp:Parameter Name="PassWord" Type="String" />
                                                    <asp:Parameter Name="Mail" Type="String" />
                                                    <asp:Parameter Name="Original_ID" Type="Int32" />
                                                </UpdateParameters>
                                                <SelectParameters>
                                                    <asp:CookieParameter CookieName="Account" Name="AccountID" Type="String" />
                                                </SelectParameters>
                                                <InsertParameters>
                                                    <asp:Parameter Name="AccountID" Type="String" />
                                                    <asp:Parameter Name="Account" Type="String" />
                                                    <asp:Parameter Name="PassWord" Type="String" />
                                                    <asp:Parameter Name="Mail" Type="String" />
                                                </InsertParameters>
                                            </asp:ObjectDataSource>
                                            <telerik:RadComboBox ID="Level3RadComboBox" Runat="server" 
                                                AppendDataBoundItems="True" datasourceid="Level2Account" 
                                                DataTextField="Account" DataValueField="Account" 
                                                onselectedindexchanged="Level3RadComboBox_SelectedIndexChanged" Width="300px">
                                            </telerik:RadComboBox>
                                            <asp:ObjectDataSource ID="Level2Account" runat="server" DeleteMethod="Delete" 
                                                OldValuesParameterFormatString="original_{0}" 
                                                SelectMethod="GetDataByAccountL2ID" 
                                                TypeName="AccountsDataSetTableAdapters.AccountL3TableAdapter">
                                                <DeleteParameters>
                                                    <asp:Parameter Name="Original_ID" Type="Int32" />
                                                </DeleteParameters>
                                                <SelectParameters>
                                                    <asp:ControlParameter ControlID="Level2RadComboBox" Name="AccountL2ID" 
                                                        PropertyName="SelectedValue" Type="Int32" />
                                                </SelectParameters>
                                            </asp:ObjectDataSource>
                                            <asp:HiddenField ID="Level3HiddenField" runat="server" 
                                                Value='<%# Bind("Level2Account") %>' />
                                            <br />
                                            <br />
                                            </span></span>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridButtonColumn ButtonType="PushButton" CommandName="Edit" 
                                        FilterControlAltText="Filter column2 column" Text="Edit" UniqueName="column2">
                                        <HeaderStyle Width="40px" />
                                    </telerik:GridButtonColumn>
                                    <telerik:GridButtonColumn ButtonType="PushButton" CommandName="Delete" 
                                        ConfirmText="Are you sure that you want to delete this record?" 
                                        FilterControlAltText="Filter column1 column" Text="Delete" UniqueName="column1">
                                        <HeaderStyle Width="40px" />
                                    </telerik:GridButtonColumn>
                                </Columns>
                                <editformsettings>
                                    <editcolumn ButtonType="PushButton" 
                                        filtercontrolalttext="Filter EditCommandColumn column" 
                                        uniquename="EditCommandColumn1">
                                    </editcolumn>
                                </editformsettings>
                                <EditFormSettings>
                                    <EditColumn ButtonType="PushButton" UniqueName="EditCommandColumn">
                                    </EditColumn>
                                </EditFormSettings>
                            </mastertableview>
                            <filtermenu enableimagesprites="False">
                            </filtermenu>
                            <headercontextmenu cssclass="GridContextMenu GridContextMenu_Default">
                            </headercontextmenu>
                        </telerik:RadGrid> 
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 23 May 2012, 03:19 PM
Hello,

Please check below code snippet its working correctly.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
       >
           <MasterTableView>
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn DataField="Level1Account" FilterControlAltText="Filter Level1Account column"
                       HeaderText="HSG" SortExpression="Level1Account" UniqueName="Level1Account">
                       <EditItemTemplate>
                           <telerik:RadComboBox ID="Level2RadComboBox" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Level2RadComboBox_SelectedIndexChanged"
                               Width="300px">
                               <Items>
                                   <telerik:RadComboBoxItem Text="1" Value="1" />
                                   <telerik:RadComboBoxItem Text="2" Value="2" />
                                   <telerik:RadComboBoxItem Text="3" Value="3" />
                               </Items>
                           </telerik:RadComboBox>
                           <telerik:RadComboBox ID="Level3RadComboBox" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Level3RadComboBox_SelectedIndexChanged"
                               Width="300px">
                               <Items>
                                   <telerik:RadComboBoxItem Text="11" Value="11" />
                                   <telerik:RadComboBoxItem Text="22" Value="22" />
                                   <telerik:RadComboBoxItem Text="33" Value="33" />
                               </Items>
                           </telerik:RadComboBox>
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
               <EditFormSettings>
                   <EditColumn ButtonType="PushButton" FilterControlAltText="Filter EditCommandColumn column"
                       UniqueName="EditCommandColumn1">
                   </EditColumn>
               </EditFormSettings>
               <EditFormSettings>
                   <EditColumn ButtonType="PushButton" UniqueName="EditCommandColumn">
                   </EditColumn>
               </EditFormSettings>
           </MasterTableView>
       </telerik:RadGrid>
Protected Sub Level3RadComboBox_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    Dim Level3RadComboBox As RadComboBox = TryCast(sender, RadComboBox)
    Dim item As GridEditFormItem = TryCast(Level3RadComboBox.NamingContainer, GridEditFormItem)
    Dim Level2RadComboBox As RadComboBox = TryCast(item.FindControl("Level2RadComboBox"), RadComboBox)
    ' You can access both combobox here
 
End Sub
Protected Sub Level2RadComboBox_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
 
    Dim Level2RadComboBox As RadComboBox = TryCast(sender, RadComboBox)
    Dim item As GridEditFormItem = TryCast(Level2RadComboBox.NamingContainer, GridEditFormItem)
    Dim Level3RadComboBox As RadComboBox = TryCast(item.FindControl("Level3RadComboBox"), RadComboBox)
    ' You can access both combobox here
End Sub
 
 
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    Dim dt As DateTime = DateTime.Now
 
    Dim data As dynamic = New () {New With { _
        .ID = 1, _
        .Name = "Name_1", _
        .customdate = dt, _
        .NO = 11.0 _
    }, New With { _
        .ID = 2, _
        .Name = "Name2", _
        .customdate = dt, _
        .NO = 11.0 _
    }, New With { _
        .ID = 3, _
        .Name = "Name3", _
        .customdate = dt, _
        .NO = 11.0 _
    }, New With { _
        .ID = 4, _
        .Name = "Name4", _
        .customdate = dt, _
        .NO = 11.44 _
    }, New With { _
        .ID = 5, _
        .Name = "Name5", _
        .customdate = dt, _
        .NO = 10.4 _
    }}
 
    RadGrid1.DataSource = data
End Sub

Let me know if any concern.


Thanks,
Jayesh Goyani
0
Dwight
Top achievements
Rank 1
answered on 24 May 2012, 02:39 AM

Thank you so much x 1000

I wish I could buy you a beer or coffee :)

I really appreciate your effort
Tags
Grid
Asked by
Dwight
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Dwight
Top achievements
Rank 1
Share this question
or