i want to acess all the child columns of each and every parent column

1 Answer 166 Views
Grid
deepak
Top achievements
Rank 1
deepak asked on 10 Jul 2022, 10:18 AM
<%@ Page Language="C#" Title="Manage City Records" AutoEventWireup="true" CodeFile="Cities.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="admin_Cities" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main1" runat="Server">

    <telerik:RadWindowManager RenderMode="Lightweight" runat="server" ID="RadWindowManager1"></telerik:RadWindowManager>
    <script type="text/javascript">

        function alertCallBackFn(arg) {
            //console.log(arg);


        }

    </script>

    <!-- PAGE HEADER -->
    <div class="container-fluid page-header-container">
        <div class="row page-header-row">
            <div class="col page-header-col-left">
                <h1>Manage City Records</h1>
            </div>
        </div>
    </div>
    <!-- / PAGE HEADER -->

    <div class="dataList">
        <div class="container-fluid">
            <div class="row">
                <div class="col">
                    <form id="form1">
                        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                            <AjaxSettings>
                                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                                    <UpdatedControls>
                                        <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                                    </UpdatedControls>
                                </telerik:AjaxSetting>
                            </AjaxSettings>
                        </telerik:RadAjaxManager>
                        <div id="demo" class="demo-container no-bg">
                            <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" ShowStatusBar="true"
                                AutoGenerateColumns="False" PageSize="10" AllowSorting="True" AllowMultiRowSelection="False"
                                AllowPaging="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                                AllowAutomaticUpdates="True" OnItemUpdated="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted"
                                OnItemInserted="RadGrid1_ItemInserted" OnInsertCommand="RadGrid1_InsertCommand"
                                OnItemCreated="RadGrid1_ItemCreated" OnPageIndexChanged="RadGrid1_PageIndexChanged" OnLoad="RadGrid1_Load">
                                <PagerStyle Mode="NumericPages"></PagerStyle>
                                <MasterTableView DataSourceID="SqlDataSource1" PageSize="10" DataKeyNames="ID" Width="100%" CommandItemDisplay="Top" Name="City">
                                    <DetailTables>
                                        <telerik:GridTableView DataKeyNames="ID" DataSourceID="SqlDataSource2" Width="100%"
                                            runat="server" CommandItemDisplay="Top" Name="CityLookup">
                                            <ParentTableRelation>
                                                <telerik:GridRelationFields DetailKeyField="CityID" MasterKeyField="ID"></telerik:GridRelationFields>
                                            </ParentTableRelation>
                                            <Columns>
                                                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn2">
                                                    <HeaderStyle Width="20px"></HeaderStyle>
                                                    <ItemStyle CssClass="MyImageButton"></ItemStyle>
                                                </telerik:GridEditCommandColumn>
                                                <telerik:GridBoundColumn SortExpression="ID" HeaderText="ID" HeaderButtonType="TextButton"
                                                    DataField="ID" UniqueName="ID" ReadOnly="true">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn SortExpression="re_city_id" HeaderText="City ID" HeaderButtonType="TextButton"
                                                    DataField="re_city_id" UniqueName="CityID" ReadOnly="true">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn SortExpression="OriginalCity" HeaderText="Original City" HeaderButtonType="TextButton"
                                                    DataField="OriginalCity" UniqueName="OriginalCity">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn SortExpression="OriginalStprov" HeaderText="Original State/Province"
                                                    HeaderButtonType="TextButton" DataField="OriginalStprov" UniqueName="OriginalStprov">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn SortExpression="OriginalCountry" HeaderText="Original Country" HeaderButtonType="TextButton"
                                                    DataField="OriginalCountry" UniqueName="OriginalCountry">
                                                </telerik:GridBoundColumn>
                                                 <telerik:GridCheckBoxColumn  HeaderText="Enable Correction" HeaderButtonType="TextButton"
                                                    DataField="EnableCorrection" UniqueName="EnableChildCorrection" DataType="System.Boolean" >
                                                </telerik:GridCheckBoxColumn>
                                                <telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this record from re_citylookup?"
                                                    CommandName="Delete" Text="Delete" UniqueName="DeleteColumn2">
                                                    <HeaderStyle Width="20px"></HeaderStyle>
                                                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                                                </telerik:GridButtonColumn>
                                            </Columns>
                                            <SortExpressions>
                                                <telerik:GridSortExpression FieldName="OriginalCity"></telerik:GridSortExpression>
                                            </SortExpressions>
                                        </telerik:GridTableView>
                                    </DetailTables>
                                    <Columns>
                                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
                                            <HeaderStyle Width="20px"></HeaderStyle>
                                            <ItemStyle CssClass="MyImageButton"></ItemStyle>
                                        </telerik:GridEditCommandColumn>
                                        <telerik:GridBoundColumn SortExpression="ID" HeaderText="ID" HeaderButtonType="TextButton"
                                            DataField="ID" UniqueName="ID" ReadOnly="true">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn SortExpression="City" HeaderText="City" HeaderButtonType="TextButton"
                                            DataField="City" UniqueName="City">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn SortExpression="State" HeaderText="State" HeaderButtonType="TextButton"
                                            DataField="State" UniqueName="State">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton"
                                            DataField="Country" UniqueName="Country">
                                        </telerik:GridBoundColumn>
                                          <telerik:GridCheckBoxColumn  HeaderText="Enable Correction" HeaderButtonType="TextButton"
                                                    DataField="EnableCorrection" UniqueName="EnableCorrection" DataType="System.Boolean">
                                                </telerik:GridCheckBoxColumn>
                                        <telerik:GridButtonColumn ConfirmText="Deleting this record from re_city will also remove child records from re_citylookup table. Are you sure you want to delete this?"
                                            CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                                            <HeaderStyle Width="20px"></HeaderStyle>
                                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                                        </telerik:GridButtonColumn>
                                    </Columns>
                                    <SortExpressions>
                                        <telerik:GridSortExpression FieldName="City"></telerik:GridSortExpression>
                                    </SortExpressions>
                                </MasterTableView>
                            </telerik:RadGrid>
                        </div>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                            DeleteCommand="DELETE FROM [dbo].[re_citylookup] WHERE [re_city_id] = @ID; DELETE FROM [dbo].[re_city] WHERE [ID] = @ID"
                            InsertCommand="IF(((SELECT COUNT(1) FROM [dbo].[re_city] WHERE [City] = @City AND [State] = @State AND [Country] = @Country) = 0) AND ((SELECT COUNT(1) FROM [dbo].[re_citylookup] WHERE [OriginalCity] = @City AND [OriginalStprov] = @State AND [OriginalCountry] = @Country) = 0)) BEGIN INSERT INTO [dbo].[re_city] ([City], [State], [Country]) VALUES (@City, @State, @Country); INSERT INTO [dbo].[re_citylookup]([re_city_id], [OriginalCity], [OriginalStprov], [OriginalCountry]) SELECT TOP 1 ID, @City, @State, @Country FROM [dbo].[re_city] WHERE [City] = @City AND [State] = @State AND [Country] = @Country ORDER BY ID DESC; END; ELSE BEGIN THROW 99001, 'City Already Exists', 1; END;"
                            SelectCommand="SELECT * FROM [dbo].[re_city]"
                            UpdateCommand="UPDATE [dbo].[re_city] SET [City] = @City, [State] = @State, [Country] = @Country WHERE [ID] = @ID">
                            <DeleteParameters>
                                <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
                            </DeleteParameters>
                            <InsertParameters>
                                <asp:Parameter Name="City" Type="String"></asp:Parameter>
                                <asp:Parameter Name="State" Type="String"></asp:Parameter>
                                <asp:Parameter Name="Country" Type="String"></asp:Parameter>
                            </InsertParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="City" Type="String"></asp:Parameter>
                                <asp:Parameter Name="State" Type="String"></asp:Parameter>
                                <asp:Parameter Name="Country" Type="String"></asp:Parameter>
                                <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
                               
                            </UpdateParameters>
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                            DeleteCommand="DELETE FROM [dbo].[re_citylookup] WHERE [ID] = @ID"
                            InsertCommand="IF((SELECT COUNT(1) FROM [dbo].[re_citylookup] WHERE [OriginalCity] = @OriginalCity AND [OriginalStprov] = @OriginalStprov AND [OriginalCountry] = @OriginalCountry) = 0) BEGIN INSERT INTO [dbo].[re_citylookup] ([re_city_id], [OriginalCity], [OriginalStprov], [OriginalCountry]) VALUES (@CityID, @OriginalCity, @OriginalStprov, @OriginalCountry) END ELSE BEGIN THROW 99001, 'City Already Exists', 1; END"
                            SelectCommand="SELECT [ID], [re_city_id], [OriginalCity], [OriginalStprov], [OriginalCountry],[EnableCorrection] FROM [dbo].[re_citylookup] WHERE [re_city_id] = @CityID"
                            UpdateCommand="UPDATE [dbo].[re_citylookup] SET [OriginalCity] = @OriginalCity, [OriginalStprov] = @OriginalStprov, [OriginalCountry] = @OriginalCountry WHERE [ID] = @ID">
                            <SelectParameters>
                                <asp:Parameter Name="CityID" Type="Int32"></asp:Parameter>
                            </SelectParameters>
                            <DeleteParameters>
                                <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
                            </DeleteParameters>
                            <InsertParameters>
                                <asp:Parameter Name="CityID" Type="Int32"></asp:Parameter>
                                <asp:Parameter Name="OriginalCity" Type="String"></asp:Parameter>
                                <asp:Parameter Name="OriginalStprov" Type="String"></asp:Parameter>
                                <asp:Parameter Name="OriginalCountry" Type="String"></asp:Parameter>
                            </InsertParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="OriginalCity" Type="String"></asp:Parameter>
                                <asp:Parameter Name="OriginalStprov" Type="String"></asp:Parameter>
                                <asp:Parameter Name="OriginalCountry" Type="String"></asp:Parameter>
                                <asp:Parameter Name="ID" Type="Int32"></asp:Parameter>
                            </UpdateParameters>
                        </asp:SqlDataSource>
                    </form>
                </div>
            </div>
        </div>
    </div>

</asp:Content>

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 12 Jul 2022, 11:40 AM

Hi Deepak,

Each GridTableView in RadGrid (The MasterTableView and each nested DetailTable) expose a Columns collection - Columns. You can get a reference to each of the DetaiTables by a recursive loop as suggested in the following documentation section:

I would also recommend checking out the following resources for getting a better understanding of the specifics of Hierarchical RadGrid:

I hope this information will help you achieve the desired outcome.

Please let me know if any questions come up.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
deepak
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or