RadComboBox on Filter doesn't display selected text when using LoadOnDemand

3 posts, 1 answers
  1. Ashley
    Ashley avatar
    16 posts
    Member since:
    Feb 2012

    Posted 29 Oct 2013 Link to this post

    I have a RadFilter with multiple RadFilterDropDownEditors with DropDownType RadComboBox. All of these I've set the DataSource in the ExpressionItemCreated Event.

    Because of the size of the dataset for one of the combox boxes, I'm trying to use LoadOnDemand like so:

    protected void RadFilter1_ExpressionItemCreated(object sender, RadFilterExpressionItemCreatedEventArgs e)
    {
        var singleItem = e.Item as RadFilterSingleExpressionItem;
        if (singleItem != null && singleItem.IsSingleValue)
        {
            if(singleItem.InputControl is RadComboBox)
            {
                var dropDownList = singleItem.InputControl as RadComboBox;
     
                switch (singleItem.FieldName)
                {
                    case "Security":
                        dropDownList.EnableLoadOnDemand = true;
                        dropDownList.ShowMoreResultsBox = true;
                        dropDownList.EnableVirtualScrolling = true;
                        dropDownList.WebServiceSettings.Method = "GetSecurityNames";
                        dropDownList.WebServiceSettings.Path = "DataSetPopup.aspx";
                        break;
                }
            }
        }
    }

    This works pretty well, but as soon as I click to add a new expression or load the filter from saved data, it no longer remembers the Selected Text value - it's blank. It remembers the SelectedValue, and the numeric value appears in the Filter Expression below the control, but I need it to display the text value as well.

    Is there an event where I can get the selected value and set the Text field of the combo box?

    Here's the markup for the filter if that helps
    <rad:RadFilter runat="server" ID="RadFilter1" OnFieldEditorCreating="RadFilter1_FieldEditorCreating" OnApplyExpressions="RadFilter1_ApplyExpressions" OnExpressionItemCreated="RadFilter1_ExpressionItemCreated"  ExpressionPreviewPosition="Bottom" ShowApplyButton="false" AllowFilterOnBlur="true"  SettingsFormatter="BinaryFormatter">
         <FieldEditors>
               <rad:RadFilterDropDownEditor FieldName="Currency" DataTextField="IsoCurrencyCode" DataValueField="CurrencyId" DropDownType="RadComboBox"   />
               <rad:RadFilterDropDownEditor FieldName="Country" DataTextField="CountryDesc" DataValueField="CountryId" DropDownType="RadComboBox"/>                         
               <rad:RadFilterDropDownEditor FieldName="Region" DataTextField="RegionDesc" DataValueField="RegionId" DropDownType="RadComboBox"/>                         
               <rad:RadFilterDropDownEditor FieldName="Security" DataTextField="Security" DataValueField="SecurityId"  DropDownType="RadComboBox" />
          </FieldEditors>
    </rad:RadFilter>


  2. Ashley
    Ashley avatar
    16 posts
    Member since:
    Feb 2012

    Posted 29 Oct 2013 Link to this post

    I didn't realize the SelectedValue of the dropdownlist was already set when the ExpressionItemCreated event was fired.

    I was able to set the text doing this, but it requires a database call each time - is there a way to get the text from the combobox based on the id?

    case "Security":
       dropDownList.EnableLoadOnDemand = true;
       dropDownList.ShowMoreResultsBox = true;
       dropDownList.EnableVirtualScrolling = true;
       dropDownList.WebServiceSettings.Method = "GetSecurityNames";
       dropDownList.WebServiceSettings.Path = "DataSetPopup.aspx";
       int id;
       if(int.TryParse(dropDownList.SelectedValue, out id))
       {
           var security = GetSecurity(id);
           dropDownList.Text = security.SecurityShortName;
       }
       break;
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 01 Nov 2013 Link to this post

    Hi Ashley,

    The approach that you are currently using is correct. You could not have the access to the Text value without performing a request because the RadComboBox does not have its items when LoadOnDemand is enabled. 

    Regards,
    Antonio Stoilkov
    Telerik
    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 the blog feed now.
Back to Top