Add Custom attributes dynamically in RadComboBox

2 posts, 0 answers
  1. Olivier
    Olivier avatar
    146 posts
    Member since:
    Nov 2010

    Posted 02 Oct 2015 Link to this post

    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");
           }

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    832 posts

    Posted 07 Oct 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top