How to set a RadComboBox that is using a data source to a selected value in codebehind
Asked Answered
D

1

0

I have a RadComboBox that is bounded by a datasource. I set the datacource to select from a the database using a select query. Run I run the project, I get a complete list of items in the RadComboBox.

I want to set the RadComboBox to a selected value, or index in the codebehind. So the RadComboBox will have a value in it once the page is load, instead of it being empty.

I have tried to do this with the code like so:

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

But I get a null value in the debugger once I run the program. I have tried to put the code in the Page_Load , Page_LoadComplete, and Page_Init methods. It still comes back as an null value. Can some please tell me where I should put the code, so that it will not return a null value?

Dropout answered 11/7, 2014 at 16:20 Comment(0)
T
1

You can add a property on your viewModel for the selected item and bind the radion button's SelectedItem property to it.

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

RadComboBoxItem item = RCB_PO_NUM.FindItemByText("2000");
RCB_PO_NUM.SelectedItem = item;
Tyrocidine answered 11/7, 2014 at 16:22 Comment(9)
Looking into it now. ThanksDropout
I updated my answer. There should be DataBound event on that control.Zoography
That event handler never gets firedDropout
That means you don't bind the control at all. You should bind DataSource then the event will fire. How do you populate the items?Zoography
I set the datacource to select from a the database using a select query. I can see all the items in the list drop down of the combobox once the page is loadedDropout
I added SqlDataSourcePO_NUM.DataBind(); on the page_load method, the even still never gets firedDropout
Are you sure you attach to the event not too late? Try also the Load and PreRender events of the control itself not the page.Zoography
I had the property load on demand set to true. I like that feature. Once I set it to false the RCB_PO_NUM.DataBound, I didn't need to set the SqlDataSourcePO_NUM.DataBind(), the event fired with outDropout
I wish there was a way for me to keep the EnableLoadOnDemand property set the trueDropout

© 2022 - 2024 — McMap. All rights reserved.