get radcombobox from EditITemTemplate in a GridTemplateColumn

1 Answer 226 Views
ComboBox Grid
Dan
Top achievements
Rank 1
Dan asked on 21 Jun 2021, 07:11 PM

I have a GridTemplateColumn with a EditItemTemplate. In the editItemTemplate there is a cmbDepartment RadCombobox. In the code behind I want to get the cmbDepartment RadComboBox and then check to see if one of the items is equal to a string. If the string is not one of the text values in the RadComboBox I want to add it.

The RadComboBox loads from the Department lookup table. The data for the Grid is from a MyTable where the Department Name is stored with the rest of the record/row. If the Department Name is deleted from the lookup table I want to add the Department to the RadcomboBox when I load, or after I load the RadGrid.

 

 

 

   <telerik:RadGrid ID="rdgrdADGroupsAdmin" runat="server" OnItemDataBound="OnItemDataBoundHandler" AutoGenerateColumns="false" AllowPaging="true" Width="900px" PageSize="25" AllowSorting="True" AllowFilteringByColumn="true" GridLines="Horizontal" CssClass="ctbGridHeader">
        <GroupingSettings CaseSensitive="False" />
        <SelectedItemStyle CssClass="MySelectedClass" />
        <ClientSettings>
            <Selecting AllowRowSelect="True" />
            <Resizing EnableNextColumnResize="false" />
        </ClientSettings>
        <MasterTableView DataKeyNames="ADGroupMappingID, ADGroupName, DepartmentID, DepartmentName,  DeletedFlag" EditMode="InPlace" CommandItemDisplay="Top">
            <CommandItemSettings ShowRefreshButton="False" ShowAddNewRecordButton="True" AddNewRecordText="Add Funder Type" />
            <EditFormSettings EditColumn-ButtonType="PushButton">
            </EditFormSettings>
            <AlternatingItemStyle CssClass="MyRowClass" />
            <CommandItemTemplate>
                <div id="divButtons" style="padding: 5px 0 5px 5px">
                    <telerik:RadButton ID="btnAddDurationType" OnClientClicking="RadAddADMapping" runat="server" Text="Add Duration Type" CommandName="InitInsert">
                    </telerik:RadButton>
                     <telerik:RadButton ID="btnTEST" OnClientClicking="RadAddADMapping" runat="server" Text="Test Get Combo box" CommandName="TestComboBox">
                    </telerik:RadButton>
                </div>
            </CommandItemTemplate>
            <Columns>
                <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column" UniqueName="EditColumn"
                    ButtonType="imagebutton">
                    <ItemStyle Width="3%" />
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="ADGroupMappingID" Display="false" UniqueName="colADGroupMappingID" ReadOnly="true">
                    <HeaderStyle HorizontalAlign="Center" />
                </telerik:GridBoundColumn>
                <%--<telerik:GridBoundColumn DataField="ADGroupName" MaxLength="50" FilterControlAltText="Filter colADGroupName column" UniqueName="colADGroupName" HeaderText="Name" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"
                    FilterControlToolTip="Press Enter or Tab key to search for value entered." FilterControlWidth="90%">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Top" Width="150px" />
                     <ItemStyle  VerticalAlign="Top" Width="150px"  />
                    <ColumnValidationSettings EnableRequiredFieldValidation="true" EnableModelErrorMessageValidation="true">
                        <RequiredFieldValidator ForeColor="Red" ErrorMessage="This field is required"></RequiredFieldValidator>
                        <ModelErrorMessage BackColor="Red" />
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>--%>
                <telerik:GridTemplateColumn HeaderStyle-Width="200px" HeaderText="AD Group Name" DataType="System.String" DataField="ADGroupName" UniqueName="colADGroupName" FilterControlAltText="Filter colADGroupName column" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"
                    ShowFilterIcon="false" FilterControlToolTip="Press Enter or Tab key to search for value entered." FilterControlWidth="100%" SortExpression="ADGroupName">
                    <ItemTemplate>
                        <%#DataBinder.Eval(Container.DataItem, "ADGroupName")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="rdTxtBxcolADGroupName" runat="server" MaxLength="64" TextMode="SingleLine" Rows="1" Wrap="true" Width="80%" Text='<%# Bind("ADGroupName") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <HeaderStyle HorizontalAlign="Center" />
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="DepartmentName" HeaderText="Department" FilterControlAltText="Filter colDepartmentName column" UniqueName="colDepartmentName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"
                    FilterControlToolTip="Press Enter or Tab key to search for value entered." FilterControlWidth="90%" SortExpression="DepartmentName">
                    <ItemTemplate>
                        <%#DataBinder.Eval(Container.DataItem, "DepartmentName")%>
                    </ItemTemplate>
                    <HeaderStyle HorizontalAlign="Center" />
                    <ItemStyle Width="250px" VerticalAlign="Top" />
                    <EditItemTemplate>
                        <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="cmbDepartment" Width="300" DropDownWidth="300" DataTextField="DeptName"
                            DataValueField="DEPTLKEY" DataSourceID="dsDepartments" SelectedValue='<%#Bind("DepartmentID") %>' AppendDataBoundItems="true">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
               <%-- <telerik:GridDropDownColumn UniqueName="DropDownListColumn" ListTextField="DeptName"
                    ListValueField="DEPTLKEY" DataSourceID="dsDepartments" HeaderText="DropDown Column"
                    DataField="DepartmentName"  AllowAutomaticLoadOnDemand="true" DropDownControlType="RadComboBox" AllowSorting="true">
                </telerik:GridDropDownColumn>--%>
                <telerik:GridCheckBoxColumn UniqueName="colIsEditor" AllowFiltering="false" HeaderText="Is Editor" DataField="IsEditor">
                    <HeaderStyle HorizontalAlign="Left" Width="6%" />
                </telerik:GridCheckBoxColumn>
                <telerik:GridCheckBoxColumn UniqueName="colIsAdmin" AllowFiltering="false" HeaderText="Is Admin" DataField="IsAdmin">
                    <HeaderStyle HorizontalAlign="Left" Width="6%" />
                </telerik:GridCheckBoxColumn>
                <telerik:GridCheckBoxColumn UniqueName="colIsAllRecordsOnly" AllowFiltering="false" HeaderText="View All Records" DataField="IsAllRecordsOnly">
                    <HeaderStyle HorizontalAlign="Left" Width="6%" />
                </telerik:GridCheckBoxColumn>
                <telerik:GridButtonColumn ConfirmText="Delete this Duration Type?" ButtonType="LinkButton"
                    CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" Width="3%" />
                </telerik:GridButtonColumn>

            </Columns>
            <EditFormSettings EditColumn-ButtonType="ImageButton">
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
    <%--<asp:SqlDataSource ID="dsDepartments" runat="server" ConnectionString="<%$ ConnectionStrings:csAppDB %>" SelectCommand="GetAllActiveDepartments" SelectCommandType="StoredProcedure"></asp:SqlDataSource>--%>    
    <asp:SqlDataSource ID="dsDepartments" runat="server" ConnectionString="<%$ ConnectionStrings:csCTBUtility %>" SelectCommand="Select * from (select *, row_number() over(partition by DEPTLKEY order by DEPTSTARTDATE desc) as rn from DEPARTMENT WHERE DEPTSTARTDATE <= GETDATE() and (DEPTENDDATE IS NULL or DEPTENDDATE >= GETDATE())) as T where rn = 1 ORDER BY DEPTNAME"></asp:SqlDataSource>

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 24 Jun 2021, 09:22 AM

Hello Dan,

You had a support ticket with the same question that my colleague already answered. I just wanted to share the answer in your forum Post as well.

Here is the answer from my colleague:

"Based on the provided information I can see that the RadComboBox and the RadGrid are bound to two independent data sources. In this case, the server <%# Bind() %> expression cannot be used. 

You will need to handle the updating of the RadGrid Datasource and RadComboBox selection manually to avoid getting the error.

I have modified the sample project to demonstrate such a scenario. In the sample, the DataSource bound to the RadComboBox and the one bound to the RadGrid has just partially matching field entries, to imitate the scenario with the deleted fields of the combo's data source.

Please give it a try and inspect the implementation of the sample. One more example with manual two way binding of a combo in RadGrid you can find in the following forum post - https://www.telerik.com/forums/radcombobox-cascading-inside-radgrid#3608117"

Regards,
Attila Antal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or