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

Radio buttons in hierarchical grid.

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
regina
Top achievements
Rank 1
regina asked on 14 Sep 2012, 09:16 PM
I have a radiobutton column in the level of my hierarchical grid, when I set at a higher level I want the child levels to be set from the code behind, but I cannot get precisely the syntax to iterate the mastertable/detailtable associates with the find control.  also I am not sure if I am starting form the correct location in code, my starting point is the radiobutton index changed event, also this is not load on demand detail table, the entire grid is loaded at once.  thank you in advance for your assistance.  

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 15 Sep 2012, 04:20 PM
Hello,

Please try with below code snippet.

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadioButtonList  RadioButtonList1 = sender as RadioButtonList;
            GridDataItem item = RadioButtonList1.NamingContainer as GridDataItem;
            if (item.OwnerTableView.Name == "Parent")
            {
                // Click from parent Radiobuttonlist
                foreach (GridDataItem itemp in RadGrid1.MasterTableView.Items)
                {
                    if (Convert.ToString(item.GetDataKeyValue("ID")) == Convert.ToString(itemp.GetDataKeyValue("ID")))
                    {
                        foreach (GridDataItem itemc in itemp.ChildItem.NestedTableViews[0].Items)
                        {
                            RadioButtonList RadioButtonList1c = itemc.FindControl("RadioButtonList1") as RadioButtonList;
                            RadioButtonList1c.SelectedIndex = RadioButtonList1.SelectedIndex;
                        }
                    }
                }
            }
            else if (item.OwnerTableView.Name == "Child")
            {
                // click from child Radiobuttonlist
            }
        }
 
  protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
        {
            
            GridDataItem item = e.DetailTableView.ParentItem as GridDataItem;
            string strID = item.GetDataKeyValue("ID").ToString();
 
            dynamic data = new[] {
              new { ID = 1, Name ="aaa_"+strID},
              new { ID = 2, Name = "bbb_"+strID},
              new { ID = 3, Name = "ccc_"+strID},
              new { ID = 4, Name = "ddd_"+strID},
               new { ID = 5, Name ="eee_"+strID}
            };
 
            e.DetailTableView.DataSource = data;
        }
 
 
  protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
              new { ID = 1, Name ="aaa"},
              new { ID = 2, Name = "bbb"},
              new { ID = 3, Name = "ccc"},
              new { ID = 4, Name = "ddd"},
               new { ID = 5, Name ="eee"}
            };
            RadGrid1.DataSource = data;
        }
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
             OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" Name="Parent" HierarchyLoadMode="Client">
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                                <asp:ListItem Text="1" Value="1"></asp:ListItem>
                                <asp:ListItem Text="2" Value="2"></asp:ListItem>
                                <asp:ListItem Text="3" Value="3"></asp:ListItem>
                            </asp:RadioButtonList>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
                <DetailTables>
                    <telerik:GridTableView Name="Child">
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                                        <asp:ListItem Text="1" Value="1"></asp:ListItem>
                                        <asp:ListItem Text="2" Value="2"></asp:ListItem>
                                        <asp:ListItem Text="3" Value="3"></asp:ListItem>
                                    </asp:RadioButtonList>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
            </MasterTableView>
        </telerik:RadGrid>


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
regina
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or