RadGrid with two comboboxes in same row with data source of one depending on another selection

3 posts, 0 answers
  1. Galina
    Galina avatar
    6 posts
    Member since:
    May 2018

    Posted 04 Jun 2018 Link to this post

    I have RadGrid with EditMode="Batch". I have two columns Location and Department  and comboboxes Location and Department inside  EditItemTemplate and InsertItemTemplate. They use SqlDataSource, Location data source just query all the location records, department  data source has parameter - location id.

     

    I need to be able to update data source of Department in edit and insert mode  depending on what is  selected in the column "location". I created hidden control that is used by department data source, but can't figure out when and how to set it to rebind the Department combobox.

     

    Any help is greatly appreciated!

     <asp:HiddenField ID="hflocationid" runat="server" />

    <telerik:RadGrid ID="RadGrid3" runat="server" DataSourceID="dsCatGroup" AllowAutomaticDeletes="true"
                            GroupPanelPosition="Top" ResolvedRenderMode="Classic" OnBatchEditCommand="RadGrid2_BatchEditCommand">
                            
                            <MasterTableView AutoGenerateColumns="False" DataKeyNames="PartCatGroupID" EditMode="Batch" CommandItemDisplay="Top"
                                DataSourceID="dsCatGroup" ShowHeadersWhenNoRecords="true">
                                <BatchEditingSettings EditType="Row"  />

                                <Columns>
                                    <telerik:GridTemplateColumn HeaderText="Responsible Location" UniqueName="ResponsibleLocation" DataField="ResponsibleLocation" HeaderStyle-Width="125px" AllowFiltering="true" ShowFilterIcon="false" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="250px">
                                                    <ItemTemplate>
                                                       <%# Eval("ResponsibleLocation")%>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                         <telerik:RadComboBox ID="ddResponsibleLocation1" Runat="server" DataSourceID="dsResponsibleLocations"
                                                                    DataTextField="LocationName" DataValueField="LocationId" EmptyMessage="Select a Location"
                                                                    EnableAutomaticLoadOnDemand="True" ItemsPerRequest="20" MarkFirstMatch="True"
                                                                    ShowMoreResultsBox="True" Width="95%" AutoPostBack="False" ZIndex="20000"
                                                                    CausesValidation="False">
                                                                </telerik:RadComboBox>                       
                                                    </EditItemTemplate>
                                                    <InsertItemTemplate>
                                                        <telerik:RadComboBox ID="ddResponsibleLocation2" Runat="server" DataSourceID="dsResponsibleLocations"
                                                                    DataTextField="LocationName" DataValueField="LocationId" EmptyMessage="Select a Location"
                                                                    EnableAutomaticLoadOnDemand="True" ItemsPerRequest="20" MarkFirstMatch="True"
                                                                    ShowMoreResultsBox="True" Width="95%" AutoPostBack="False" ZIndex="20000"
                                                                    CausesValidation="False">
                                                                </telerik:RadComboBox>
                                                                                     
                                                    </InsertItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Responsible Department" UniqueName="ResponsibleDepartment" DataField="ResponsibleDepartment" HeaderStyle-Width="125px" AllowFiltering="true" ShowFilterIcon="false" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" FilterControlWidth="250px">
                                                    <ItemTemplate>
                                                       <%# Eval("ResponsibleLocation")%>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                         <telerik:RadComboBox ID="ddResponsibleDepartment1" Runat="server" DataSourceID="dsResponsibleDepartments"
                                                                    DataTextField="DepartmentCode" DataValueField="DepartmentId" EmptyMessage="Select a Department"
                                                                    EnableAutomaticLoadOnDemand="True" ItemsPerRequest="20" MarkFirstMatch="True"
                                                                    ShowMoreResultsBox="True" Width="95%" AutoPostBack="False" ZIndex="20000" OnItemDataBound="ddResponsibleDepartment1_ItemDataBound"
                                                                    CausesValidation="False">
                                                                </telerik:RadComboBox>                       
                                                         
                                                    </EditItemTemplate>
                                                    <InsertItemTemplate>
                                                        <telerik:RadComboBox ID="ddResponsibleDepartment2" Runat="server" DataSourceID="dsResponsibleDepartments"
                                                                    DataTextField="DepartmentCode" DataValueField="DepartmentId" EmptyMessage="Select a Department"
                                                                    EnableAutomaticLoadOnDemand="True" ItemsPerRequest="20" MarkFirstMatch="True"
                                                                    ShowMoreResultsBox="True" Width="95%" AutoPostBack="False" ZIndex="20000"
                                                                    CausesValidation="False">
                                                                </telerik:RadComboBox>
                                                    </InsertItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridButtonColumn CommandName="Delete" ConfirmText="Are you sure you want to delete this Product Group?" ButtonType="ImageButton" HeaderText="Delete?" ConfirmDialogType="RadWindow" UniqueName="btnDeleteFinal">
                                            <ItemStyle VerticalAlign="Middle" />
                                    <HeaderStyle Width="55px" />
                                    </telerik:GridButtonColumn>
                                </Columns>
                            </MasterTableView>
                        </telerik:RadGrid>

     

    <asp:SqlDataSource ID="dsResponsibleLocations" runat="server"
                            ConnectionString="<%$ ConnectionStrings:PPMTESTConnectionString %>"
                            SelectCommand="SELECT  [LocationId],[LocationName] FROM [PartCatLocations] ORDER BY [LocationName] ">
                        </asp:SqlDataSource>
                        <asp:SqlDataSource ID="dsResponsibleDepartments" runat="server"
                            ConnectionString="<%$ ConnectionStrings:PPMTESTConnectionString %>"
                            SelectCommand="SELECT  [DepartmentId],[DepartmentCode] FROM PartCatDepartments where LocationId=@locationid ORDER BY [DepartmentCode] ">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="hflocationid" Name="locationid"  
                                    PropertyName="Value" />
                            </SelectParameters>
                        </asp:SqlDataSource>

  2. Eyup
    Admin
    Eyup avatar
    4014 posts

    Posted 07 Jun 2018 Link to this post

    Hi Galina,

    I am afraid this requirement is not supported with Batch editing mode, which is different than other server-side modes:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-batch-edit-mode

    For this scenario you can use the InPlace edit mode instead:
    https://demos.telerik.com/aspnet-ajax/dropdowntree/examples/applicationscenarios/dropdowntreeingrid/defaultcs.aspx?product=grid%20https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/edit-mode/in-place


    You can check the samples provided in the following post:
    https://www.telerik.com/forums/radcombobox-cascading-inside-radgrid#GxsIQqyyPkqj1Za-mNbalg

    I hope this will prove helpful.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Galina
    Galina avatar
    6 posts
    Member since:
    May 2018

    Posted 07 Jun 2018 in reply to Eyup Link to this post

    Thank you
Back to Top