asp.net实现无刷新DropDownList联动

本文介绍如何在ASP.NET中实现无刷新的DropdownList联动效果,通过JavaScript和XMLHttpRequest对象发送请求,获取并更新第二个DropdownList的数据,从而提供更流畅的用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

asp.net实现无刷新DropDownList联动:   
    
   <%@    Page    language="c#"    Codebehind="Example.aspx.cs"    AutoEventWireup="false"    Inherits="Webs.other.Example"    %>     
   <HTML>     
   <HEAD>     
   <title>Example</title>     
   <meta    name="GENERATOR"    Content="Microsoft    Visual    Studio    .NET    7.1">     
   <meta    name="CODE_LANGUAGE"    Content="C#">     
   <meta    name="vs_defaultClientScript"    content="JavaScript">     
   <meta    name="vs_targetSchema"    content="http://schemas.microsoft.com/intellisense/ie5">     
   <script>     
   function    load(state){     
   var    drp2    =    document.getElementById("DropDownList2");     
   for    (i    =    drp2.length;    i    >=    0;    i--){     
   drp2.options.remove(i);     
   }     
    
   var    oHttpReq    =    new    ActiveXObject("MSXML2.XMLHTTP");     
   var    oDoc    =    new    ActiveXObject("MSXML2.DOMDocument");     
    
   oHttpReq.open("POST",    "getData.aspx?state="+state,    false);     
   oHttpReq.send("");     
   result    =    oHttpReq.responseText;     
   oDoc.loadXML(result);     
   items1    =    oDoc.selectNodes("//CITY/Table/Id");     
   items2    =    oDoc.selectNodes("//CITY/Table/shiname");     
    
   var    itemsLength=items1.length;     
     for(i=0;i<itemsLength;i++)     
    
   //将小类的类名和编号赋予DropDownList2     
     {     
     var    newOption    =    document.createElement("OPTION");     
     newOption.text=items2[i].text;     
     newOption.value=items1[i].text;     
     drp2.options.add(newOption);     
     }     
   }     
   window.onload    =    function(){load('1');}     
    
&nb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值