Add a row to a bound RadComboBox with ItemTemplate inside a RadGrid

3 posts, 0 answers
  1. SSirica
    SSirica avatar
    50 posts
    Member since:
    Jan 2007

    Posted 17 Jun 2014 Link to this post

    I have a RadComboBox (cbSCAT) that is designed with multiple columns that resides inside of a RadGrid.  It looks like this:
    <telerik:RadGrid ID="rgChartOfAccts" runat="server" Skin="Metro" CellSpacing="-1" GridLines="Both" Width="98%" AllowPaging="True">
    <ClientSettings>
        <Scrolling AllowScroll="True" SaveScrollPosition="True" UseStaticHeaders="True"></Scrolling>
    </ClientSettings>
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="COA_ID,COA_GL_ACCOUNT" CommandItemDisplay="Top"
        InsertItemPageIndexAction="ShowItemOnCurrentPage" EditMode="PopUp" Name="ChartOfAccts">
        <CommandItemSettings ShowExportToExcelButton="true" ShowRefreshButton="False" AddNewRecordText="Add new Account" />
        <RowIndicatorColumn Visible="False">
        </RowIndicatorColumn>
        <ExpandCollapseColumn Created="True">
        </ExpandCollapseColumn>
        <Columns>
        <telerik:GridEditCommandColumn ButtonType="ImageButton" Exportable="False" HeaderStyle-Width="30px" ColumnGroupName="grpCOA" />
        <telerik:GridTemplateColumn HeaderText="Account" UniqueName="COA_GL_ACCOUNT" ColumnGroupName="grpCOA">
            <EditItemTemplate>
            <telerik:RadTextBox ID="txtCOA_Acct" runat="server" Text='<%# Bind("COA_GL_ACCOUNT")%>' Width="490px" MaxLength="150"></telerik:RadTextBox>
            <asp:RequiredFieldValidator ID="rfvCOA_Acct" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="txtCOA_Acct" Text="*" Font-Size="Small" SetFocusOnError="True"></asp:RequiredFieldValidator>
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label ID="lblCOA_Acct" runat="server" Text='<%# Eval("COA_GL_ACCOUNT")%>'></asp:Label>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn HeaderText="Description" UniqueName="COA_DESCRIPTION" ColumnGroupName="grpCOA">
            <EditItemTemplate>
            <telerik:RadTextBox ID="txtCOA_Desc" runat="server" Text='<%# Bind("COA_DESCRIPTION")%>' Width="490px" MaxLength="150"></telerik:RadTextBox>
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label ID="lblCOA_Desc" runat="server" Text='<%# Eval("COA_DESCRIPTION")%>'></asp:Label>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn HeaderText="Category" UniqueName="COA_CATEGORY" ColumnGroupName="grpCOA">
            <EditItemTemplate>
            <telerik:RadTextBox ID="txtCOA_Cat" runat="server" Text='<%# Bind("COA_CATEGORY")%>' Width="490px" MaxLength="150"></telerik:RadTextBox>
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label ID="lblCOA_Cat" runat="server" Text='<%# Eval("COA_CATEGORY")%>'></asp:Label>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn HeaderText="Contra Account" UniqueName="COA_CONTRA_ACCOUNT" ColumnGroupName="grpCOA">
            <EditItemTemplate>
            <telerik:RadTextBox ID="txtCOA_Contra" runat="server" Text='<%# Bind("COA_CONTRA_ACCOUNT")%>' Width="490px" MaxLength="150"></telerik:RadTextBox>
            <asp:RequiredFieldValidator ID="rfvCOA_Contra" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="txtCOA_Contra" Text="*" Font-Size="Small" SetFocusOnError="True"></asp:RequiredFieldValidator>
            </EditItemTemplate>
            <ItemTemplate>
            <asp:Label ID="lblCOA_Contra" runat="server" Text='<%# Eval("COA_CONTRA_ACCOUNT")%>'></asp:Label>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridButtonColumn ConfirmText="Delete this Account?" ConfirmDialogType="RadWindow" ColumnGroupName="grpCOA"
            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Exportable="False" HeaderStyle-Width="30px" />
        </Columns>
        <DetailTables>
        <telerik:GridTableView Name="RateTypeAss" CommandItemDisplay="Top" DataSourceID="" EditMode="PopUp"
            DataKeyNames="RTA_ID" runat="server" Width="100%" BackColor="#FFCC66" AlternatingItemStyle-BackColor="#FFCC66"
            HeaderStyle-BackColor="#FFCC66" ClientDataKeyNames="RTA_ID,COA_GL_ACCOUNT" AutoGenerateColumns="False" ShowHeadersWhenNoRecords="True"
            EnableNoRecordsTemplate="True" NoDetailRecordsText="No Associated records to display.">
            <CommandItemSettings ShowAddNewRecordButton="True" ShowRefreshButton="False" ShowExportToExcelButton="True" AddNewRecordText="Add new Association" />
            <ParentTableRelation>
            <telerik:GridRelationFields DetailKeyField="COA_GL_ACCOUNT" MasterKeyField="COA_GL_ACCOUNT" />
            </ParentTableRelation>
            <NoRecordsTemplate>No records to display.</NoRecordsTemplate>
            <RowIndicatorColumn Visible="False">
            </RowIndicatorColumn>
            <EditFormSettings PopUpSettings-Width="600px" InsertCaption="New Association" PopUpSettings-Modal="True">
            <EditColumn ButtonType="ImageButton" />
            </EditFormSettings>                                   
            <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" Exportable="False" HeaderStyle-Width="30px" />
            <telerik:GridTemplateColumn HeaderText="Account" UniqueName="COA_GL_ACCOUNT">
                <EditItemTemplate>
                  <asp:Label ID="lblAcctA" runat="server" Text='<%# Bind("COA_GL_ACCOUNT")%>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                  <asp:Label ID="lblAcctB" runat="server" Text='<%# Eval("COA_GL_ACCOUNT")%>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
     
            <telerik:GridTemplateColumn HeaderText="List Code" UniqueName="RATE_TYPE_LIST_CODE">
                <EditItemTemplate>
                <telerik:RadComboBox ID="cbRTL" runat="server" DataSourceID="linqDS_RTL" DataTextField="RATE_TYPE_LIST_CD" DataValueField="RATE_TYPE_LIST_CD"  OnItemDataBound="cbRTL_ItemDataBound" OnSelectedIndexChanged="cbRTL_SelectedIndexChanged"
                    Skin="Metro" SelectedValue='<%#Bind("RATE_TYPE_LIST_CODE")%>' DropDownWidth="520px" Width="100px" HighlightTemplatedItems="True"
                    AutoPostBack="True" BorderStyle="Solid" BorderWidth="1px" BorderColor="Gray" Height="200px" AppendDataBoundItems="True">
                    <HeaderTemplate>
                    <table cellpadding="1" cellspacing="0" class="Main" width="485px">
                        <tr>
                        <td class="ComboHeader2" width="85px" style="text-align: left; visibility: visible;">Code</td>
                        <td class="ComboHeader2" width="350px" style="text-align: left; visibility: visible;">Description</td>
                        <td class="ComboHeader2" width="50px" style="text-align: left; visibility: visible;">Type</td>
                        </tr>
                    </table>
                    </HeaderTemplate>
                    <ItemTemplate>
                    <table cellpadding="1" cellspacing="0" class="Main" width="485px">
                        <tr>
                        <td width="85px" style="text-align: left; visibility: visible;">
                            <%#DataBinder.Eval(Container.DataItem, "RATE_TYPE_LIST_CD")%>
                        </td>
                        <td width="350px" style="text-align: left; visibility: visible;">
                            <%#DataBinder.Eval(Container.DataItem, "RATE_TYPE_LIST_DESC")%>
                        </td>
                        <td width="50px" style="text-align: left; visibility: visible;">
                            <%#DataBinder.Eval(Container.DataItem, "RATE_TYPE_LIST_TYPE")%>
                        </td>
                        </tr>
                    </table>
                    </ItemTemplate>
                    <Items>
                    <telerik:RadComboBoxItem ID="RadComboBoxItem2" runat="server" />
                    </Items>
                </telerik:RadComboBox>
              </EditItemTemplate>
              <ItemTemplate>
                  <asp:Label ID="lblRTL_Code" runat="server" Text='<%# Eval("RATE_TYPE_LIST_CODE")%>'></asp:Label>
              </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="List Description" UniqueName="RATE_TYPE_LIST_DESC">
                <EditItemTemplate>
                <telerik:RadTextBox ID="txtRTL_Desc" runat="server" Text='<%# Bind("RATE_TYPE_LIST_DESC")%>' Width="490px" MaxLength="150"></telerik:RadTextBox>
                </EditItemTemplate>
                <ItemTemplate>
                  <asp:Label ID="lblRTL_Desc" runat="server" Text='<%# Eval("RATE_TYPE_LIST_DESC")%>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Service Category" UniqueName="SCAT_CODE" HeaderStyle-Width="105px">
                <EditItemTemplate>   
                <telerik:RadComboBox ID="cbSCAT" runat="server" DataSourceID="linqDS_SCAT" DataTextField="SCAT_TYPE" DataValueField="SCAT_TYPE"
                    Skin="Metro" SelectedValue='<%#Bind("SCAT_CODE")%>' DropDownWidth="520px" Width="100px" HighlightTemplatedItems="True"
                    BorderStyle="Solid" BorderWidth="1px" BorderColor="Gray" Height="200px" AppendDataBoundItems="True" OnDataBound="cbSCAT_DataBound">
                    <HeaderTemplate>
                    <table cellpadding="1" cellspacing="0" class="Main" width="485px">
                        <tr>
                        <td class="ComboHeader2" width="85px" style="text-align: left; visibility: visible;">Code</td>
                        <td class="ComboHeader2" width="350px" style="text-align: left; visibility: visible;">Description</td>
                        </tr>
                    </table>
                    </HeaderTemplate>
                    <ItemTemplate>
                    <table cellpadding="1" cellspacing="0" class="Main" width="485px">
                        <tr>
                        <td width="85px" style="text-align: left; visibility: visible;">
                            <%# If(Container.DataItem IsNot Nothing, DataBinder.Eval(Container.DataItem, "SCAT_TYPE"), DataBinder.Eval(Container, "Value"))%>
                        </td>
                        <td width="350px" style="text-align: left; visibility: visible;">
                            <%# If(Container.DataItem IsNot Nothing, DataBinder.Eval(Container.DataItem, "SCAT_DESC"), DataBinder.Eval(Container, "Text"))%>
                        </td>
                        </tr>
                    </table>
                    </ItemTemplate>
                </telerik:RadComboBox>
              </EditItemTemplate>
              <ItemTemplate>
                  <asp:Label ID="lblSCAT" runat="server" Text='<%# Eval("SCAT_CODE")%>'></asp:Label>
              </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Jurisdiction" UniqueName="JURISDICTION" HeaderStyle-Width="105px">
                <EditItemTemplate>
                <telerik:RadComboBox ID="cbJuris" runat="server" Skin="Metro" SelectedValue='<%#Bind("JURISDICTION")%>' DropDownWidth="50px"
                    Width="50px" HighlightTemplatedItems="True" BorderStyle="Solid" BorderWidth="1px" BorderColor="Gray">
                    <Items>
                    <telerik:RadComboBoxItem Value="" Text="" Selected="true" />
                    <telerik:RadComboBoxItem Value="B" Text="B" />
                    <telerik:RadComboBoxItem Value="L" Text="L" />
                    <telerik:RadComboBoxItem Value="N" Text="N" />
                    </Items>
                </telerik:RadComboBox>
                </EditItemTemplate>
                <ItemTemplate>
                  <asp:Label ID="lblRTL_Juris" runat="server" Text='<%# Eval("JURISDICTION")%>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="List Type" UniqueName="RATE_TYPE_LIST_TYPE" HeaderStyle-Width="105px">
                <EditItemTemplate>
                <telerik:RadComboBox ID="cbRTL_Type" runat="server" Skin="Metro" SelectedValue='<%#Bind("RATE_TYPE_LIST_TYPE")%>' DropDownWidth="50px"
                    Width="50px" HighlightTemplatedItems="True" BorderStyle="Solid" BorderWidth="1px" BorderColor="Gray">
                    <Items>
                    <telerik:RadComboBoxItem Value="" Text="" Selected="true" />
                    <telerik:RadComboBoxItem Value="D" Text="D" />
                    <telerik:RadComboBoxItem Value="N" Text="N" />
                    <telerik:RadComboBoxItem Value="R" Text="R" />
                    <telerik:RadComboBoxItem Value="S" Text="S" />
                    <telerik:RadComboBoxItem Value="T" Text="T" />
                    <telerik:RadComboBoxItem Value="X" Text="X" />
                    </Items>
                </telerik:RadComboBox>
                </EditItemTemplate>
                <ItemTemplate>
                  <asp:Label ID="lblRTL_Type" runat="server" Text='<%# Eval("RATE_TYPE_LIST_TYPE")%>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn Visible="False" EditFormHeaderTextFormat="">
                <EditItemTemplate>
                  <asp:Label ID="lblErr" runat="server" Text= Font-Bold="True" ForeColor="Red"></asp:Label>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmDialogType="RadWindow" ConfirmText="Delete this Association?" ConfirmTitle="Delete" Exportable="False" HeaderStyle-Width="30px" />
            </Columns>
            <AlternatingItemStyle BackColor="#FFCC66" />
            <HeaderStyle BackColor="#FFCC66" />
        </telerik:GridTableView>
        </DetailTables>
        <EditFormSettings PopUpSettings-Width="600px" PopUpSettings-Modal="True" InsertCaption="New Account" PopUpSettings-ShowCaptionInEditForm="False">
        <EditColumn ButtonType="ImageButton" />
        </EditFormSettings>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnPopUpShowing="PopUpShowing2" />
    </ClientSettings>
    </telerik:RadGrid>

    I add a extra row to cbSCAT using the following code:
    Protected Sub cbSCAT_DataBound(sender As Object, e As EventArgs)
        Dim combo As RadComboBox = DirectCast(sender, RadComboBox)
        Dim item As RadComboBoxItem = New RadComboBoxItem("ALL", "XX")
        combo.Items.Insert(0, item)
        item.DataBind()
    End Sub

    It's adding to the Combobox ok except when I chose to edit a grid row with the "extra row", ie the "XX" row, the edit window doesn't even popup.  If I chose Add new record it shows up in the combobox ok like it should.  If I chose to edit a row with a value from the datasource the popup edit window comes up just fine.  

    What am I missing?
  2. SSirica
    SSirica avatar
    50 posts
    Member since:
    Jan 2007

    Posted 19 Jun 2014 in reply to SSirica Link to this post

    Never mind I've moved past this.  Now I'm just trying to get the "Export to Excel" working correctly.  
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Jun 2014 Link to this post

    Hello,

    As far as I understand you have resolved the issue with the RadComboBox control and now you are facing a problem with the RadGrid export to excel functionality. Could you please elaborate a bit more on the problem you are facing?


    Regards,
    Boyan Dimitrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top