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

房东的猫 提交于 2019-12-13 04:14:37

问题


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?


回答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;


来源:https://stackoverflow.com/questions/24702270/how-to-set-a-radcombobox-that-is-using-a-data-source-to-a-selected-value-in-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!