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

How to find a grid command item at runtime

1 Answer 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron Miles
Top achievements
Rank 1
Ron Miles asked on 05 Jan 2011, 08:44 PM
I  have a complex scenario where I have a RadGrid that contains a GridTableView, and that GridTableView needs a RadComboBox in the CommandItemTemplate whose item list needs to load dynamically based on the selected item in the parent grid.  When an item is selected in the combo, it needs to insert a record into the GridTableView.  The grid looks something like:

<telerik:RadGrid ID="MeetingRoomsGrid" runat="server" OnDetailTableDataBind="MeetingRoomsGrid_DetailTableDataBind">
    <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="Id" EditMode="InPlace" InsertItemPageIndexAction="ShowItemOnFirstPage">
        <CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true" ShowExportToPdfButton="true" ShowExportToCsvButton="true" />
        <DetailTables>
            <telerik:GridTableView DataKeyNames="Id" Name="Aggregates" Width="100%" AllowSorting="true" AllowFilteringByColumn="true" CommandItemDisplay="Top">
                <CommandItemTemplate>
                    <div style="float: right;">
                        <telerik:RadComboBox  ID="AggregateRoomCombo" runat="server" AutoPostBack="true" OnSelectedIndexChanged="AggregateRoomCombo_SelectedIndexChanged">
                            <Items>
                                <telerik:RadComboBoxItem Text="foo" />
                                <telerik:RadComboBoxItem Text="bar" />
                            </Items>
                        </telerik:RadComboBox>

                    </div>
                    <div class="clearfix">&nbsp;</div>
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridBoundColumn DataField="ChildName" DataType="System.String" UniqueName="ChildName" SortExpression="ChildName" />
                    <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ButtonType="ImageButton">
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                    </telerik:GridButtonColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridEditCommandColumn UniqueName="EditColumn" ButtonType="ImageButton">
                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
            </telerik:GridEditCommandColumn>
            <telerik:GridTemplateColumn DataField="Name"
                DataType="System.String"
                UniqueName="Name"
                SortExpression="Name"
                DefaultInsertValue="New Meeting Room"
                ItemStyle-Width="210">
                <ItemTemplate>
                    <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
                </ItemTemplate>
           </telerik:GridTemplateColumn>
       </Columns>
    </MasterTableView>
</telerik:RadGrid>

(I have stripped out a bunch of stuff to try to pare it down to the essential essence)

So on the MeetingRoomsGrid_DetailDataBind() event I need to find the AggregateRoomCombo and load items into it based on the Id of the selected data item in the grid, and on the AggregateRoomCombo_SelectedIndexChanged() event I need to insert a new record into the detail table based on the Id of the selected data item in the grid.

Can anyone tell me how to traverse the grid object model to 1) find the AggregateRoomCombo object in the detail table, and 2) traverse backwards from the AggregateRoomCombo up to the grid to find the Id of the selected data item?

1 Answer, 1 is accepted

Sort by
0
Ron Miles
Top achievements
Rank 1
answered on 06 Jan 2011, 01:38 AM
I got it all working by using the ItemCreated event to find the combo on creation and then saving it to a variable I could call once the grid databinds.  It took a little smoke and mirrors, but it all works fine now.
Tags
Grid
Asked by
Ron Miles
Top achievements
Rank 1
Answers by
Ron Miles
Top achievements
Rank 1
Share this question
or