How to set up RadComboBox that uses a data source for a selected value in codebehind

I have a RadComboBox limited to a data source. I set the data source to select from the database using the select query. Launch I run the project, I get a complete list of elements in RadComboBox.

I want to set RadComboBox to the selected value or index in the code. That way, RadComboBox will make a difference in it when the page loads, not empty.

I tried to do this with the following code:

RadComboBoxItem item = RCB_PO_NUM.FindItemByText("2000"); item.Selected = true; 

But I get a null value in the debugger after running the program. I tried to put the code in the Page_Load , Page_LoadComplete and Page_Init . It still returns as a null value. Can someone tell me where should I put the code so that it doesn't return null?

0
c # code-behind radcombobox rad-controls
source share
1 answer

You can add a property to your viewModel for the selected item and bind the property of the SelectedItem button to it.

Alternatively try this code in the RCB_PO_NUM.DataBound event RCB_PO_NUM.DataBound .

 RadComboBoxItem item = RCB_PO_NUM.FindItemByText("2000"); RCB_PO_NUM.SelectedItem = item; 
+1
source share

All Articles