zoukankan      html  css  js  c++  java
  • 读取服务器数据填充Select下拉列表[原创]

    test.html
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        
    <title>测试</title>
        
    <script type="text/javascript">
            
    var xmlhttp;
                    
    function getSubmodule()
                    
    {
                            xmlhttp 
    = new ActiveXObject("Msxml2.XMLHTTP");
                            xmlhttp.open(
    "get","Rss_SubModule.aspx",true);
                            xmlhttp.setRequestHeader(
    "Content-Type","application/x-www-form-urlencoded");
                            xmlhttp.onreadystatechange 
    = ShowList;
                            xmlhttp.send(
    null);
                    }

                    
                    
    function ShowList()
                    
    {
                        
    if(xmlhttp.readyState == 4)
                        
    {
                            
    if(xmlhttp.status == 200)
                            
    {
                               doc 
    = new ActiveXObject("Msxml2.DOMDocument")
                               doc.loadXML(xmlhttp.responseText);
                                
    var items = doc.getElementsByTagName("SubModule");
                                
                                
    var s = document.getElementById("Select1");
                                
    for(var i= 0;i < items.length;i++)
                               
    {
                                    
    var op = document.createElement("option");
                                    op.value 
    = items[i].getElementsByTagName("SubModuleID")[0].firstChild.nodeValue;
                                    
    var tx = document.createTextNode(items[i].getElementsByTagName("SubModuleName")[0].firstChild.nodeValue);
                                    op.appendChild(tx);
                                    s.appendChild(op);
                               }

                            }

                            
    else
                            
    {
                                alert(xmlhttp.status 
    +" : "+ xmlhttp.statusText);
                            }

                                                   
                        }

                    }

        
    function displayText()
        
    {
             
    for(var i=0 ;i< document.getElementById("Select1").options.length;i++)
             
    {
                
    if(document.getElementById("Select1").options[i].selected)
                
    {
                    alert(document.getElementById(
    "Select1").options[i].value);
                }

             }

        }


       
    </script>
    </head>
    <body>
        
    <input id="Button1" type="button" value="button" onclick="getSubmodule()" />
        
    <select id="Select1" onchange="displayText()">
        
    </select>
    </body>
    </html>

    Rss_SubModule.aspx
    using System;
    using System.Data;
    using System.Text;
    using System.Xml;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class Rss_SubModule : System.Web.UI.Page
    {
        
    protected void Page_Load(object sender, EventArgs e)
        
    {
    ();
            xml.PutSubModule();
        }

        
    private void PutSubModule()
        
    {
            SubModule sub 
    = new SubModule();
            DataSet ds 
    = sub.GetSubModule();
            XmlTextWriter w 
    = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
            w.WriteStartDocument();
            w.WriteStartElement(
    "GetSubModule");
            
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            
    {
                w.WriteStartElement(
    "SubModule");
                w.WriteElementString(
    "SubModuleID", ds.Tables[0].Rows[i][0].ToString());
                w.WriteElementString(
    "SubModuleName", ds.Tables[0].Rows[i][1].ToString());
                w.WriteEndElement();
            }

            w.WriteEndElement();
            w.WriteEndDocument();
            ds.Dispose();
            w.Close();
        }

    }
  • 相关阅读:
    ssm框架整合入门系列——删除-员工的删除
    ssm框架整合入门系列——修改-员工的修改
    git新建分支并推送至远程仓库库
    想带你去火星看日出
    offsetTop无法获取目标display为none的值
    Vue axios 读取api.github.com展示用户信息
    ssm框架整合入门系列——新增-员工的添加
    课时10:列表:一个打了激素的数组1
    课时9:了不起的分支和循环3
    课时8:了不起的分支和循环2
  • 原文地址:https://www.cnblogs.com/ghx88/p/435428.html
Copyright © 2011-2022 走看看