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

DropDownWidth customizing on server-side - problem

3 Answers 46 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dariusz
Top achievements
Rank 1
Dariusz asked on 09 Nov 2011, 12:35 PM
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>


3 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 14 Nov 2011, 09:14 AM
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
0
Dariusz
Top achievements
Rank 1
answered on 14 Nov 2011, 11:16 AM
Hello Dimitar,


any workarounds?
0
Dimitar Terziev
Telerik team
answered on 16 Nov 2011, 12:36 PM
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
Tags
ComboBox
Asked by
Dariusz
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Dariusz
Top achievements
Rank 1
Share this question
or