如何在数据绑定的RadComboBox中添加其他RadComboBoxItem? [英] How to add an additional RadComboBoxItem to data bound RadComboBox?
问题描述
我正在aspx页面上使用Telerik控件.我有级联的radcombo框(下拉框).我的页面上有3个.第2 rad组合框的值取决于第1个,第3个rad组合框的值取决于第2个的选择.问题是我想在第3个下拉列表中包含全选选项.这些值来自数据库,即所有值都是数据绑定的.如何在组合框中添加全选"选项?我在c#中使用parameters.insert函数尝试了它,但是不起作用.我尝试添加控件本身,但没有显示出来.
I am using Telerik controls on my aspx page. I have cascading radcombo boxes(dropdown box). I have 3 of them on my page. the values of 2nd rad combo box depends on the 1st and the 3rd depends on selection of 2nd. The thing is that i want to include a select all option in the 3rd dropdown. The values are coming from a database i.e all of them are data bound. How can i add a 'select all' option in the combo boxes? i tried it using parameters.insert function in c#, but does not work. i tried adding in the control itself but not showing up with that either.
有人可以帮忙吗?
推荐答案
简单创建一个新的RadComboBoxItem并将其添加到RadComboBox.参见下面的示例.
Simple create a new RadComboBoxItem and add it to the RadComboBox. See example below.
RadComboBoxItem myItem = new RadComboBoxItem();
myItem.Text = "Select All";
myItem.Value = "SelectAll";
//Add it as the last item
myComboBox.Items.Add(myItem);
//OR
/Add it as the first item
myComboBox.Insert(0, myItem);
编辑
通过将我们的代码放入控件的DataBound事件中,确保在绑定控件之后添加项目:
Make sure you're adding the item after the control has been bound by putting our code in the DataBound event of the control:
protected void RadComboBox1_DataBound(object sender, EventArgs e)
{
var combo = (RadComboBox)sender;
combo.Items.Insert(0, new RadComboBoxItem("Select All", "SelectAll"));
}
Here's some documentation from Telerik that explains how to do this properly: http://www.telerik.com/help/aspnet-ajax/combobox-insert-default-item-when-databinding.html.
注意:如果上述方法无效,请确保已设置myComboBox.AppendDataBoundItems = true
.
NOTE: If the above method does not work, make sure you have set myComboBox.AppendDataBoundItems = true
.
这篇关于如何在数据绑定的RadComboBox中添加其他RadComboBoxItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!