DropDownWidth customizing on server-side - problem

4 posts, 0 answers
  1. Dariusz
    Dariusz avatar
    35 posts
    Member since:
    Jul 2010

    Posted 09 Nov 2011 Link to this post

    Hello everybody,

    I have a problem with setting the DropDownWidth property from server-side.

    I use RadComboBox as a FilterTemplate on my RadGrid.

    this is what I launch when I click RadComboBox:

    protected void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
            {
                Current_rcb_Width = 0;
                if (((RadComboBox)o).DataTextField == "nazwa_")
                    ((RadComboBox)o).DataSource = GetDataTable("SELECT DISTINCT " + ((RadComboBox)o).DataTextField + jezyk + " as nazwa_ FROM katalog_produktow WHERE " + ((RadComboBox)o).DataTextField + jezyk + " LIKE '" + e.Text + "%' order by " + ((RadComboBox)o).DataTextField + jezyk);
                else
                    ((RadComboBox)o).DataSource = GetDataTable("SELECT DISTINCT " + ((RadComboBox)o).DataTextField + " FROM katalog_produktow WHERE " + ((RadComboBox)o).DataTextField + " LIKE '" + e.Text + "%' order by " + ((RadComboBox)o).DataTextField);
     
     
                var cbox = ((RadComboBox)o);
                int MaxWidth = 0;
     
                foreach (DataRow row in (((RadComboBox)o).DataSource as DataTable).Rows)
                {
                    int Width = TextWidth(row[((RadComboBox)o).DataTextField].ToString());
                    if (Width > MaxWidth)
                    {
                        MaxWidth = Width;
                    }
                }
                cbox.DropDownWidth = new Unit(MaxWidth);
                ((RadComboBox)o).DataBind();
            }

    and I checked that the code properly changed the DropDownWidth property but the size of the DropDown is still the same.
    I believe I've put the code in wrong place. 

    I tried using the code from:
    http://www.telerik.com/community/code-library/aspnet-ajax/combobox/dynamic-dropdown-width.aspx

    but it didn't work. It ran 2 times (don't know why).

    During 1st time It doesn't find any Items in RadComboBox so it's setting the DropDownWidth as 155px (initial value from code).
    During 2nd time it found all elements and calculated the proper width. It did set the property but on page it was still visible as 155px.

    Here's my ComboBox code:

    <telerik:RadComboBox ID="rcbnazwa" runat="server" ShowToggleImage="false" EnableLoadOnDemand="true" OnItemsRequested="list_ItemsRequested" OnDataBound="RadComboBox1_DataBound"
                                    MarkFirstMatch="true" Skin="Office2007" OnSelectedIndexChanged="rcbContinents_SelectedIndexChanged" DataTextField="nazwa_" Font-Size="X-Small"
                                    DataValueField="nazwa_" OnPreRender="rcbContinents_PreRender" AutoPostBack="true" Width="100%">
                                </telerik:RadComboBox>


  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 14 Nov 2011 Link to this post

    Hello Dariusz,

    The code that you are using is valid, but as you have mentioned you have placed is in the wrong place. By default in the ItemsRequested event handler you could not modify or get the current state of other controls on the page including the RadComboBox itself.

    As you could noticed the RadComboBox from the code library doesn't have load on demand.

    What you want to achieve as a functionality is not supported when load on demand is used.

    Regards,
    Dimitar Terziev
    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
  3. Dariusz
    Dariusz avatar
    35 posts
    Member since:
    Jul 2010

    Posted 14 Nov 2011 Link to this post

    Hello Dimitar,


    any workarounds?
  4. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 16 Nov 2011 Link to this post

    Hello Dariusz,

    When the RadComboBox initiates a request for items, a callback to the server is made. This is not a regular post-back and this is why you can't update the control. What you want to achieve is not supported in cases when load on demand is used.

    Kind regards,
    Dimitar Terziev
    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
Back to Top