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

Add Custom attributes dynamically in RadComboBox

1 Answer 582 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Olivier
Top achievements
Rank 2
Olivier asked on 02 Oct 2015, 04:45 PM

Hello,

 I need to add programmatically Custom Attributes in RadComboBox

 i get an error on click button to get a value for custom Attributes

 this.LBL_MOVIE.Text = this.PCB_MOVIE.SelectedItem.Attributes["movie_p"]; 

Cause this.PCB_MOVIE.SelectedIndex is equals to -1

protected void PCB_MOVIE_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
       {
           e.Item.Attributes.Add("movie_p","rocky");
       }

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 07 Oct 2015, 08:17 AM
Hello,

The RadComboBox' SelectedIndex property will return -1 if none of its items is selected. If at that moment you use it to access an item in the ComboBox' items collection, for example:
string attr = RadComboBox1.Items[RadComboBox1.SelectedIndex].Attributes["movie_p"];
an ArgumentOutOfRangeException exception will be returned.
If an item is selected the SelectedIndex property will correctly return its index and you will be able to use the property's value.

Regards,
Ivan Danchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Olivier
Top achievements
Rank 2
Answers by
Ivan Danchev
Telerik team
Share this question
or