This is a migrated thread and some comments may be shown as answers.

RadGrid ComboBox PostBack Problem

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gullo
Top achievements
Rank 1
Gullo asked on 21 May 2012, 09:28 AM
Hi,

I have a strange problem with my RadGrid. I placed to RadComboBoxes

<telerik:GridTemplateColumn UniqueName="Dossier" SortExpression="Identification"
    HeaderText="<%$Resources:ESTV.A3, LabelDossier%>" DataField="Identification"
    CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" ShowFilterIcon="false"
    ShowSortIcon="True">
    <ItemTemplate>
        <a href="<%# Eval("Case.Url") %>">
            <%# Eval("Case.Identification") %></a>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox runat="server" ID="comboBoxDossier" AllowCustomText="True" EnableLoadOnDemand="True"
            EnableVirtualScrolling="False" AutoPostBack="True" ShowMoreResultsBox="True"
            CausesValidation="False"
            EmptyMessage="<%$Resources:ESTV.A3, MessageSearchForDossierEmpty%>" Skin="Office2010Blue"
            Width="200px" MaxHeight="100px" ItemsPerRequest="50" OnItemsRequested="ComboBoxDossierItemsRequested"
            OnSelectedIndexChanged="ComboBoxDossierOnSelectedIndexChanged">
        </telerik:RadComboBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidatorDossier" runat="server" ControlToValidate="comboBoxDossier"
            ErrorMessage="<%$Resources:ESTV.A3, MessageMandatoryField%>"></asp:RequiredFieldValidator>
    </EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Address" SortExpression="FullName" HeaderText="Adressen"
    DataField="FullName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
    ShowFilterIcon="false" ShowSortIcon="True">
    <ItemTemplate>
        <a href="ViewAddress.aspx?id=<%#Eval("Address.Id") %>">
            <%# Eval("Address.FullName") %>
        </a>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox runat="server" ID="comboBoxAddress" AllowCustomText="True" EnableLoadOnDemand="True"
            EnableVirtualScrolling="False" AutoPostBack="True" ShowMoreResultsBox="True"
            CausesValidation="False"
            EmptyMessage="<%$Resources:ESTV.A3, MessageSearchForAddressEmpty%>" Skin="Office2010Blue"
            Width="200px" MaxHeight="100px" ItemsPerRequest="50" OnItemsRequested="ComboBoxAddressItemsRequested"
            OnSelectedIndexChanged="ComboBoxAddressOnSelectedIndexChanged">
        </telerik:RadComboBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidatorAddress" runat="server" ControlToValidate="comboBoxAddress"
            ErrorMessage="<%$Resources:ESTV.A3, MessageMandatoryField%>"></asp:RequiredFieldValidator>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

The Logic about this to ComboBoxes is that if I select a Value from the first one, the second one will automatically filled with the values that are in context with the first one. This is the Code that is in the OnSelectedIndexChanged Method

AddressCaseRelationBll addressCaseRelationBll = new AddressCaseRelationBll();
           AddressBll addressBll = new AddressBll();
           RadComboBox comboBoxDossiers = o as RadComboBox;
 
           if (comboBoxDossiers == null)
           {
               return;
           }
 
           try
           {
               if (string.IsNullOrEmpty(comboBoxDossiers.SelectedValue))
               {
                   List<Address> addresses = addressBll.Select();
                   RadComboBox comboBoxAddress = (RadComboBox)this.radGridAddressCaseRelation.MasterTableView.GetInsertItem().FindControl(ControlAddress);
 
                   comboBoxAddress.Items.Clear();
                   foreach (Address address in addresses)
                   {
                       comboBoxAddress.Items.Add(
                           new RadComboBoxItem(
                               address.FullName, address.Id.ToString()));
                   }
               }
               else
               {
                   List<AddressCaseRelation> addressCaseRelations = addressCaseRelationBll.SelectByCase(new Guid(comboBoxDossiers.SelectedValue));
                   RadComboBox comboBoxAddress = (RadComboBox)this.radGridAddressCaseRelation.MasterTableView.GetInsertItem().FindControl(ControlAddress);
 
                   comboBoxAddress.Items.Clear();
                   if (string.IsNullOrEmpty(comboBoxAddress.SelectedValue))
                   {
                       foreach (AddressCaseRelation addressCaseRelation in addressCaseRelations)
                       {
                           comboBoxAddress.Items.Add(
                               new RadComboBoxItem(
                                   addressCaseRelation.Address.FullName, addressCaseRelation.Address.Id.ToString()));
                       }
                   }
               }
           }

This is working fine, but if I select for example the Value A in the first comboBox, my method will add the all the items  in context with A in the second ComboBox.
Now if i open the second ComboBox see all the correct Items. At the bottom it is an Arrow for load more items.... and here is my problem. everytime when i click this arrow the items are added another time. but if i debug all my method where i have a Items.Add statement it never stops. Now i don't know where this items will bi added.

Regards

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 24 May 2012, 08:31 AM
Hello,

Most probably the problem comes from the fact that you are adding the items in the SelectedIndexChanged event. As it shown in this online demo you should fill the items collection of RadComboBox in the OnItemsRequested event.

Give this suggestion a try and check whether the issue is resolved.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Gullo
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or