在codebehind使用数据源到一选定值一个radcombob

在codebehind使用数据源到一选定值一个radcombob

本文介绍了如何设置在codebehind使用数据源到一选定值一个radcombobox控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由数据源为界的radcombobox控件。我用一个选择查询设置datacource从数据库中选择。运行我运行该项目,我得到了radcombobox控件项目的完整列表。

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.

欲的radcombobox控件设置到选定的值,或者在codebehind索引。所以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.

我曾尝试与code像这样做到这一点:

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

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

但我得到调试一个空值当我运行该程序。我曾试图把code在的Page_Load Page_LoadComplete Page_Init 方法。它仍然回来为空值。有的可以请告诉我,我应该把code,所以它不会返回空值?

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?

推荐答案

您可以在您的视图模型添加属性选定项目和radion按钮的的SelectedItem 属性绑定到吧。

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

或者尝试在 RCB_PO_NUM.DataBound 事件处理这个code。

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

RadComboBoxItem item = RCB_PO_NUM.FindItemByText("2000");
RCB_PO_NUM.SelectedItem = item;

这篇关于如何设置在codebehind使用数据源到一选定值一个radcombobox控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:24