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>