C# 从网络服务填充后将项目添加到 Telerik Ajax RadComboBox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/888686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add Items to Telerik Ajax RadComboBox after populated from webservice
提问by Ryu
I'm using the latest 2009 RadCombobox Ajax control and I'm using the build in functionality to populate it from a webservice.
我正在使用最新的 2009 RadCombobox Ajax 控件,并且我正在使用内置功能从 Web 服务填充它。
I would also like to push one more item to the box so the user has the choice of not choosing anything. Essentially making the control optional. Right now if they choose something and then change their mind, they can't change it back to nothing at all.
我还想再推一个项目到盒子里,这样用户就可以选择不选择任何东西。本质上使控件成为可选的。现在,如果他们选择了某样东西,然后又改变了主意,他们根本无法将它变回一无所有。
Everytime I've tried adding something it doesn't work or completely clears what was populated from the webservice. And I don't want the webservice to return and empty item just to make the control work.
每次我尝试添加一些东西时,它都不起作用或完全清除了从网络服务中填充的内容。而且我不希望网络服务返回并清空项目只是为了使控制工作。
<telerik:RadComboBox ID="combo" runat="server"
Skin="Office2007"
AllowCustomText="false"
EnableLoadOnDemand="true"
AppendDataBoundItems="true"
Text=""
Width="300" Height="200">
<ExpandAnimation Type="None" />
<CollapseAnimation Type="None" />
<WebServiceSettings Path="~/Service.asmx" Method="GetStuff" />
</telerik:RadComboBox>
Thanks
谢谢
采纳答案by Magnus Johansson
Is it something like this you have had in mind? Add an extra item after the data has been loaded.
你有没有想过这样的事情?加载数据后添加一个额外的项目。
<script type="text/javascript">
//<![CDATA[
function OnClientItemsRequested(sender, eventArgs) {
var combo = $find("<%= RadComboBox1.ClientID %>");
var intextput = "<All Items>";
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(intextput);
comboItem.set_value("-1");
combo.trackChanges();
combo.get_items().add(comboItem);
comboItem.select();
combo.commitChanges();
comboItem.scrollIntoView();
}
//]]>
</script>
<telerik:RadComboBox runat="server" ID="RadComboBox1"
EnableLoadOnDemand="true"
OnClientItemsRequesting="OnClientItemsRequesting"
OnClientItemsRequested="OnClientItemsRequested">
<WebServiceSettings Method="GetMyData" Path="http://localhost:1606/Service1.asmx" />
</telerik:RadComboBox>
回答by marijne
Further to Magnus' answer, to add the item to the top you would do
进一步马格努斯的回答,将项目添加到顶部,你会做
combo.get_items().insert(0, comboItem);
Client-side documentation is here:
客户端文档在这里:
http://www.telerik.com/help/aspnet-ajax/combo_clientsideradcomboboxitemcollection.html
http://www.telerik.com/help/aspnet-ajax/combo_clientsideradcomboboxitemcollection.html