绑定ASP:带有javascript数组的下拉列表 [英] Binding ASP:dropdownlist with javascript array

查看:90
本文介绍了绑定ASP:带有javascript数组的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想将asp:dropdownlist的数据源设置为Javascript数组。

数据以JavaScript格式提取并存储在数组中。现在我想将下拉列表DataSource设置为Javascript数组。





Hi All,

I want to set the asp:dropdownlist's datasource to Javascript array.
Data is fetched in JavaScript and stored in the array. Now I want to Set the dropdownlist DataSource to Javascript Array.


function showResults(results) {
         var resultItems = [];
         var resultCount = results.features.length;
         for (var i = 0; i < resultCount; i++) {
             var featureAttributes = results.features[i].attributes;
             for (var attr in featureAttributes) {
             resultItems.push("" + attr + ":  " + featureAttributes[attr] + "<br>");
           }
           resultItems.push("<br>");
         }
         dom.byId("info").innerHTML = resultItems.join("");







< asp:DropDownList ID =ddlLocationrunat =server >

< asp:ListItem Text =XYZValue =XYZi>





我尝试过:



在Script中声明函数并尝试绑定




<asp:DropDownList ID="ddlLocation" runat="server">
<asp:ListItem Text="XYZ" Value="XYZi">


What I have tried:

Declared the function in Script and try to bind

推荐答案

你必须在客户端这样做。



获取客户端下拉列表的一种方法:

You have to do it on the client side.

One way to get the dropdownlist on the client side:
var ddl_location = document.getElementById("<%=ddlLocation.ClientID%>");





然后使用数组数据填充下拉列表:



Then populate the dropdownlist with array data:

if ddl_location {
    for (var i=0; i < month.length;++i){    
        addOption(ddl_location, some_text_variable, some_value_variable);
    }
}

addOption = function(selectbox, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);  
}


这篇关于绑定ASP:带有javascript数组的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆