SelectedItem server side - no errors but no selection either

2 posts, 0 answers
  1. Karl Wilkens
    Karl Wilkens avatar
    206 posts
    Member since:
    Oct 2012

    Posted 04 May 2011 Link to this post

    Hi,

    we have radcombobox inside a user control (scheduler AdvancedEdit to be exact from a sample on your site). We are populating the RCB with values easily enough and passing a value to set the selected item as follows

     public int EventTypeId
            {
                get
                {
                  
                        return Convert.ToInt32(ResrcbActivityType.SelectedValue);
                   
                }

                set
                {
                    try
                    {
                        RadComboBoxItem itm = new RadComboBoxItem();

                        if (value > 0)
                            itm = ResrcbActivityType.FindItemByValue(Convert.ToString(value));
                        if (itm != null)
                        {
                            itm.Selected = true;
                        }
                   
                    }
                    catch (Exception ex)
                    {
                    }
                    
                }
            }

    When debugging the value when we set is non zero which is correct, the itm object is a valid radComboBoxItem object and itm.Selected = true; evaluates without error. However, the first item in the radcomboBox list is always displayed no matter what. I am guessing this is something stupid - please anyone?
  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 09 May 2011 Link to this post

    Hi Karl,

    Thank you for contacting us.

    From what you have provided as a code snippet, it seems that you are trying to select an items which is not in the items collection of the RadCombobox, but having only a reference to such an item.

    In order to select the desired item change your code as following:
    try
            {
                RadComboBoxItem itm = new RadComboBoxItem();
     
                if (value > 0)
                    itm = ResrcbActivityType.FindItemByValue(Convert.ToString(value));
                if (itm != null)
                {
                    ResrcbActivityType.FindItemByValue(Convert.ToString(value)).Selected = true;
                }
     
            }
            catch (Exception ex)
            {
            }

    I hope this would help you out.

    Regards,
    Dimitar Terziev
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top