65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 jQuery 在 RadComboBox 中添加多个项目

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1投票)

2014年12月24日

CPOL
viewsIcon

13156

使用 jQuery 在 RadComboBox 中添加多个项目

引言

通常,在 Telerik 网站中绑定 Telerik RadComboBox 时,只能提供一个项目。但是,这里我使用 jQuery 添加了多个项目到 RadComboBox 中。

首先,我在服务器端绑定 Rccolname,然后在 OnClientDropDownClosed 事件中绑定另一个 RadCombobox

因此,我首先创建一个名为 rccolname 的函数,该函数获取 Rccolname 下拉框的索引,并将其设置为 rccoltype 下拉框的值。

之后,获取选定的值后,我使用 switch case 条件,在每个 case 中将值插入到数组中。然后,我使用 For 循环将项目插入到 Rcombooperator 中。


 function rccolnameChange(sender, args) {
         var item = args._domEvent.target.innerText
         var index = sender._selectedIndex;
         var rccoltyp = $find("<%= rcColType.ClientID %>");
         rccoltyp._selectedIndex = index; //set index of RcColtype Conmbo
         var rccol = $find("<%= rcColType.ClientID %>");
         var name = rccol._childListElement.childNodes[index].innerText;// Get Selected Index Text
            
           if (index != 0) {
               var selectitem = new Array();
                switch (name.toLowerCase()) {
                    case 'datetime': case 'system.datetime':
                        selectitem.push("=");
                        selectitem.push(">");
                        selectitem.push("<");
                        selectitem.push("<=");
                        selectitem.push(">=");
                        selectitem.push("<>");
                        selectitem.push("IS NULL");
                        selectitem.push("IS NOT NULL");
                        selectitem.push("BETWEEN");
                        break;
                    case 'numeric': case 'decimal':
                        selectitem.push("=");
                        selectitem.push(">");
                        selectitem.push("<");
                        selectitem.push("<=");
                        selectitem.push(">=");
                        selectitem.push("<>");
                        selectitem.push("IS NULL");
                        selectitem.push("IS NOT NULL");
                        selectitem.push("Browse");
                        break;
                    case 'varchar': case 'string': case 'system.string': case 'char':
                        selectitem.push("=");
                        selectitem.push("<>");
                        selectitem.push("IS NULL");
                        selectitem.push("IS NOT NULL");
                        selectitem.push("End With");
                        selectitem.push("contains");
                        selectitem.push("Browse");
                        break;
                }

                var combo = $find("<%= RComboOperator.ClientID %>");
                combo.clearItems();
                var length = selectitem.length
                for (i = 0; i < selectitem.length; i++) {
                    var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                    
                    comboItem.set_text(selectitem[i]);
                    combo.trackChanges();
                    combo.get_items().add(comboItem);
                    combo.commitChanges();
                    comboItem.select();
                }
            }
        }
© . All rights reserved.