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

Set SelectedVaon page load eventlue property

1 Answer 49 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Edwin
Top achievements
Rank 1
Edwin asked on 09 Feb 2011, 10:52 AM
I need to set RadComboBox SelectedValue property with URL parameter value:

ComboBox OnLoad event:
someComboBox.DataSource = GetDataList();
someComboBox.DataBind();

ComboBox OnDataBound event:
someComboBox.ClearSelection();
someComboBox.Text = string.Empty;
someComboBox.SelectedValue = valueFromUrlParameter;

After page loads ComboBox is populated with data from GetDataList(), but selected value is first item in the list. It is intersting if i step through these methods in debugging mode, then value is correctly selected.

1 Answer, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 10 Feb 2011, 10:09 PM
Hi Edwin,

I suppose that this happens because the RadComboBox that you use is read-only.
When the control is read-only there is always a selected item in it - and at initial page load this is the  first item.

If you want to set the selected item at RadComboBox using some value obtained from Url - you can handle the OnDataBound event in this way:
protected void someComboBox_DataBound(object sender, EventArgs e)
{
    var someComboBox = (RadComboBox)sender;
    someComboBox.Items.FindItemByValue("valueFromUrlParameter").Selected = true;
}

Regards,
Kalina
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
Edwin
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Share this question
or