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

SelectedItem server side - no errors but no selection either

1 Answer 39 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Karl Wilkens
Top achievements
Rank 1
Karl Wilkens asked on 04 May 2011, 08:16 PM
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?

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 09 May 2011, 02:56 PM
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.

Tags
ComboBox
Asked by
Karl Wilkens
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question
or