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

[Solved] Q2 2009 obscure problem with SelectedValue and OnItemsRequested

1 Answer 91 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
brian
Top achievements
Rank 1
brian asked on 03 Sep 2009, 11:09 AM
Hi

Thought Id share an issue I had today with combobox's that are related like the example at http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx

Basically if you add items to the code infront like this:

            <telerik:RadComboBox ID="RadComboBox3"   
                runat="server"   
                Width="186px"   
                CssClass="ComboBox_Cities"   
                OnClientItemsRequested="ItemsLoaded"   
                OnItemsRequested="RadComboBox3_ItemsRequested" 
                AppendDataBoundItems="true"   
                ShowMoreResultsBox="false" 
                NoWrap="true" 
                EnableScreenBoundaryDetection="false"   
                EmptyMessage="Type a city name"   
                AllowCustomText="false"   
                MarkFirstMatch="true">  
                <Items> 
                    <telerik:RadComboBoxItem Text="other, please specify" Value="-1" /> 
                </Items> 
            </telerik:RadComboBox>    

Then you will not get a SelectedValue returned when you submit the form. You get the Text property but not SelectedValue. Solution is to add these default RadComboBoxItems after you have databound the others in the OnItemsRequested handler.

Not sure if this is an actual issue with the control, or that a warning needs to be put somewhere, but this is something Im sure others would want to do in future.

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 18 Sep 2009, 12:06 PM
Hello brian,

Thank you for letting us know about this issue.

Indeed, there should not be a difference in the behavior of RadComboBox (i.e. its properties should return equal values) between the two ways of adding this default Item.

I logged this bug and updated your Telerik points for reporting it.

As a workaround, you can create the default Item at the client on the control's load and the server-side ItemsRequested event:

        function onLoad(sender) { 
            addDefaultItem(sender).select(); 
        } 
         
        function addDefaultItem(comboBox) { 
            var item = new Telerik.Web.UI.RadComboBoxItem(); 
            item.set_text("choose, please specify"); 
            item.set_value("-1"); 
             
            comboBox.get_items().insert(0, item); 
             
            return item; 
        } 

All the best,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ComboBox
Asked by
brian
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or