xmlHttpRequest.responseXML设置DropDownList选项

Page

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default18.aspx.cs" Inherits="Default18" %>

<!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 runat="server">
    <title>Untitled Page</title>

    <script type="text/javascript">
    var xmlHttp;
    function createXMLHttpRequest()
    {
       
        try
        {   //from IE old version. below version 6.0
            xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
        }catch(e)
        {
            try
            {   //from IE.version 6.0 /7.0
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e2)
            {   //from firefox
                xmlHttp=new XMLHttpRequest();
            }
        }
    }

    function startRequest()
    {
        createXMLHttpRequest();

        var selectoptions=document.all("rblOption");
        var selectvalue;
        for(i=0;i<selectoptions.length;i++)
        {
            if(selectoptions[i].checked)
            {
                selectvalue=selectoptions[i].value;
            }
        }

        xmlHttp.onreadystatechange = handleStateChange;
        xmlHttp.open("GET", "Handler.ashx?para=" +selectvalue, true);
        xmlHttp.send(null);
    }

    function handleStateChange()
    {
        if(xmlHttp.readyState == 4) //4 return data success
        {
            if(xmlHttp.status == 200) //200(OK);404(not found)
            {
                var blist=document.getElementById("ddlData");
                blist.length=0;
               
                var rs = xmlHttp.responseXML.childNodes[1];
                var ss=rs.getElementsByTagName("student");
   
              for(var i=0;i<ss.length;i++)
              {
                var option = document.createElement("OPTION");
                option.text = ss[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
                option.value = ss[i].getElementsByTagName("sex")[0].childNodes[0].nodeValue;
                blist.options.add(option);
                }
            }
        }
    }
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <asp:RadioButtonList ID="rblOption" runat="server">
            <asp:ListItem>A</asp:ListItem>
            <asp:ListItem>B</asp:ListItem>
            <asp:ListItem>C</asp:ListItem> 
        </asp:RadioButtonList>
        <asp:DropDownList ID="ddlData" runat="server"></asp:DropDownList>
    </form>
</body>
</html>

 

 

using System;
using System.Data;
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 Default18 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.rblOption.Attributes.Add("onclick", "startRequest();");          
        }
    }
}

 

 

 

Generic Handler

 

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/xml";
        context.Response.Write("<?xml version='1.0' encoding='utf-8' ?><root><student><name>" + context.Request["para"] + "</name><sex>M</sex></student><student><name>wah2</name><sex>M</sex></student></root>");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值