如何在ASP .NET中动态地向下拉列表添加选项 [英] How to add options to the drop down dynamically in ASP .NET

查看:65
本文介绍了如何在ASP .NET中动态地向下拉列表添加选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的下拉列表我需要在1到30的第一个下拉列表中添加选项,我需要动态地向下拉1到100添加选项我该怎么做?



Below is my dropdown i need to add options to the first dropdown from 1 to 30 and I need to add options to the drop down 1 to 100 dynamically how can I do this?

<script type="text/javascript">
       function GetDynamicTextBox(value) {
           if (value == "") {
               return '<input name = "DynamicTextBox" type="text" value = "' + value + '" />  <Select id="ddlID" name = "DynamicTextDropdown"></Select>  <Select name = "DynamicTextDropdown"></Select>' +
                ' <input id="btnAdd123" type="button" value="Add" onclick="AddTextBox()" /><input type="button" value="Remove" onclick = "RemoveTextBox(this)" />'
           }

       }
       debugger;
       function GetDynamicTextBox1(value, i) {
           debugger;
           return '<input name = "DynamicTextBox" type="text" value = "' + value + '" />  <input name = "DynamicTextDropdown" id="ddlID" type="value" value = "' + i + '" />' +
                      ' <input id="btnAdd123" type="button" value="Add" onclick="AddTextBox()" /><input type="button" value="Remove" onclick = "RemoveTextBox(this)" />'
       }
       function AddTextBox() {
           var div = document.createElement('DIV');
           div.innerHTML = GetDynamicTextBox("");
           document.getElementById("TextBoxContainer").appendChild(div);
       }
       function AddTextBox1() {
           var inputCount = document.getElementById('TextBoxContainer').getElementsByTagName('input').length;
           if (inputCount == "0") {
               var div = document.createElement('DIV');
               div.innerHTML = GetDynamicTextBox("");
               document.getElementById("TextBoxContainer").appendChild(div);
           }

       }
       function RemoveTextBox(div) {
           document.getElementById("TextBoxContainer").removeChild(div.parentNode);
       }

       function RecreateDynamicTextboxes() {
           var values = eval('<%=Values%>');
           if (values != null) {
               var html = "";
               for (var i = 0; i < values.length; i += 2) {
                   html += "<div>" + GetDynamicTextBox1(values[i], values[i + 1]) + "</div>";
               }
               document.getElementById("TextBoxContainer").innerHTML = html;
           }
       }
       window.onload = RecreateDynamicTextboxes;
   </script>
    <script type="text/javascript">


        $(document).ready(function () {
            debugger;
            var selectHTML = "";
            for (i = 1; i < 101; i++) {
                selectHTML += "<option value='" + i + "'>" + i + "</option>";
            }


            $("#ddlID").empty();
            $("#ddlID").append(selectHTML);
        });
   </script>





我的尝试:



i找不到这样做的来源



What I have tried:

i could not find the source for doing this

推荐答案

(document).ready(function(){
debugger;
var selectHTML =;
for(i = 1; i< 101; i ++){
selectHTML + =< option value ='+ i +'>+ i + < / option>;
}
(document).ready(function () { debugger; var selectHTML = ""; for (i = 1; i < 101; i++) { selectHTML += "<option value='" + i + "'>" + i + "</option>"; }


(#ddlID)。empty();
("#ddlID").empty();


(#ddlID )。append(selectHTML);
});
< / script>
("#ddlID").append(selectHTML); }); </script>





我的尝试:



i无法找到执行此操作的来源



What I have tried:

i could not find the source for doing this


这篇关于如何在ASP .NET中动态地向下拉列表添加选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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