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

[Solved] SelectedIndex is set when it shouldn't be

1 Answer 145 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sean Overman
Top achievements
Rank 1
Sean Overman asked on 03 Aug 2009, 06:51 PM
I'm using a RadComboBox with a definition like this:
<tel:RadComboBox ID="ChooseCustomer" runat="server" Width="200" DropDownWidth="300"  EmptyMessage="Type a customer name" AllowCustomText="true" MarkFirstMatch="true" > 
     <CollapseAnimation Duration="50" /> 
     <ExpandAnimation Duration="50" /> 
</tel:RadComboBox> 

in the code behind:
During page load and ! postback... something like this:
IList<Customer> all = EntityPersister.GetAll<Customer>(); 
ChooseCustomer.DataSource = all
ChooseCustomer.DataTextField = "CustomerName"
ChooseCustomer.DataValueField = "ID"
ChooseCustomer.DataBind(); 

now... the problem comes when a CustomerName is a blank string.

in a subsequent postback, then SelectedIndex property is set to the first "Blank" databound item.  but the front end still says "Type a customer name" 

Obviously the user has not changed the drop down, but its still reporting erroneously that the selected index is chosen.

Thanks
Sean

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 06 Aug 2009, 01:00 PM
Hello Sean Overman,

Well this is expected behavior, the description of the EmptyMessage property is as follows:
"EmptyMessage is displayed when the text is empty".

What do you want to happen when item with no text is selected? RadComboBox displaying empty string? If so, you can do that via setting the Text property of the RadCombo to 1 interval string i.e. to " ".

if (RadComboBox1.SelectedItem.Text == string.Empty) 
        { 
            RadComboBox1.SelectedItem.Text = " "
        } 



Regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ComboBox
Asked by
Sean Overman
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or