• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

ASP.net DropDownList 无刷新联动!

发布: 2007-7-01 11:09 | 作者: admin | 来源: | 查看: 109次 | 进入软件测试论坛讨论

领测软件测试网  <TITLE>WebForm2</TITLE>

  <SCRIPT language=@#javascript@#>
  function load(){
    var drp2 = document.getElementById("DropDownList2");
    drp2.innerText="";
    for(var i = 0;i<=drp2.options.length -1;i++){
     drp2.remove(i);
    }
    var drp3 = document.getElementById("DropDownList3");
    for(var i = 0;i<=drp3.options.length -1;i++){
     drp3.remove(i);
    }
    var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
    var oDoc = new ActiveXObject("MSXML2.DOMDocument");
    var state=document.getElementById("DropDownList1").value;
    xmlhttp.open("POST", "webform1.aspx?id="+state,false);
    xmlhttp.send("");
    var res=oDoc.loadXML(xmlhttp.responseText);
    var naItems = oDoc.selectNodes("//Market/Table/maName");
    var idItems = oDoc.selectNodes("//Market/Table/maId");
    var item;
    var id;
    for (item = naItems.nextNode(),id=idItems.nextNode(); item&&id; item = naItems.nextNode(),id=idItems.nextNode()){
     var nastr = item.nodeTypedValue;
     var idstr = id.nodeTypedValue;
     var newOption = document.createElement("OPTION");
     newOption.text =nastr;
     newOption.value = idstr;
     
     
     drp2.options.add(newOption);
    }
    load2();
  
  }
  function load2(){
    var drp2 = document.getElementById("DropDownList3");
    drp2.innerText="";
    for(var i = 0;i<=drp2.options.length -1;i++){
     drp2.remove(i);
    }
    var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
    var oDoc = new ActiveXObject("MSXML2.DOMDocument");
    var state=document.getElementById("DropDownList2").value;
    xmlhttp.open("POST", "webform3.aspx?id="+state,false);
    xmlhttp.send("");
    var res=oDoc.loadXML(xmlhttp.responseText);
    var naItems = oDoc.selectNodes("//Market/Table/maName");
    var idItems = oDoc.selectNodes("//Market/Table/maId");
    var item;
    var id;
    for (item = naItems.nextNode(),id=idItems.nextNode(); item&&id; item = naItems.nextNode(),id=idItems.nextNode()){
     var nastr = item.nodeTypedValue;
     var idstr = id.nodeTypedValue;
     var newOption = document.createElement("OPTION");
     newOption.text =nastr;
     newOption.value = idstr;
     
     
     drp2.options.add(newOption);
    }
  
  }
  </SCRIPT>
 </HEAD>
 <BODY ms_positioning="GridLayout" onload="load()">
  <FORM id="Form1" method="post" runat="server">
   <ASP:DROPDOWNLIST id="DropDownList1" runat="server"></ASP:DROPDOWNLIST>
   <ASP:DROPDOWNLIST id="DropDownList2" runat="server"></ASP:DROPDOWNLIST>
   <ASP:DROPDOWNLIST id="Dropdownlist3" runat="server"></ASP:DROPDOWNLIST>
  </FORM>
 </BODY>
</HTML>
-----------------------
namespace dropDown
{
 /// <summary>
 /// WebForm2 的摘要说明。
 /// </summary>
 public class WebForm2 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.DropDownList DropDownList1;
  protected System.Web.UI.WebControls.DropDownList Dropdownlist3;
  protected System.Web.UI.WebControls.DropDownList DropDownList2;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!this.IsPostBack)
   {
    SqlConnection con = new SqlConnection("server=localhost;database=star;uid=sa;pwd=");
    SqlDataAdapter da = new SqlDataAdapter("select maId,maName from tabMarket  where maCls=0",con);
    DataSet ds = new DataSet();
    da.Fill(ds,"op");
    this.DropDownList1.DataSource=ds.Tables[0];
    this.DropDownList1.DataTextField = "maName";
    this.DropDownList1.DataValueField = "maId";
    this.DropDownList1.DataBind();
    this.DropDownList1.Attributes.Add("onchange","load()");
    this.DropDownList2.Attributes.Add("onchange","load2()");
   }


  }

 }
}
-----------------------
public class WebForm1 : System.Web.UI.Page
 {
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   // Put user code to initialize the page here
   //if(this.Request["state"]!=null)
   //{ 
     string id =this.Request["id"];
    SqlConnection con = new SqlConnection("server=localhost;database=star;uid=sa;pwd=;");
    SqlDataAdapter da = new SqlDataAdapter("select maName,maId  from tabMarket where maParent=@id and maSt=1 ",con);
       da.SelectCommand.Parameters.Add("@id",id);
    DataSet ds = new DataSet("Market");
    da.Fill(ds);
   
       ds.WriteXml(Response.OutputStream);
       Response.Flush ();
       Response.End ();
      
   //}
  }
       }
-----------------------------
 public class WebForm3 : System.Web.UI.Page
 {
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   string id =Request["id"];
   SqlConnection con = new SqlConnection("server=localhost;database=star;uid=sa;pwd=;");
   SqlDataAdapter da = new SqlDataAdapter("select maName,maId  from tabMarket where maParent=@id and maSt=1",con);
   da.SelectCommand.Parameters.Add("@id",id);
   DataSet ds = new DataSet("Market");
   da.Fill(ds);
   
   ds.WriteXml(Response.OutputStream);
   Response.Flush ();
   Response.End ();
  }
       }
------------------


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网