欢迎光临
我们一直在努力

再谈 N 个 ASP.net DropDownList 无刷新联动菜单-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

再谈 n 个 asp.net dropdownlist 无刷新联动菜单,牺牲n-1个aspx来实现自动更新机制,避免刷新的闪动!!

以下代码绝对可以使用,也可以实现多级菜单。。。。


  <script language=”javascript”>
   function load(state)
   {
    var drp2 = document.getelementbyid(“dropdownlist2”);
    for(var i=0;i<=drp2.options.length-1;i++)
    {
     drp2.remove(i);
    }
    var ohttpreq = new activexobject(“msxml2.xmlhttp”);    //发送请求
    var odoc = new activexobject(“msxml2.domdocument”);    //响应结果
    var state=document.getelementbyid(“dropdownlist1”).value;
    ohttpreq.open(“post”,”webform2.aspx?state=”+state, false);
    ohttpreq.send(“”);
    result = ohttpreq.responsetext;
    odoc.loadxml(result); 
    
   // items = odoc.selectnodes(“//city/table”);
       items = odoc.selectnodes(“//address/table”);
     for (var item = items.nextnode();item;item = items.nextnode())
     { 
      var city = item.selectsinglenode(“//address”).nodetypedvalue;
      var newoption = document.createelement(“option”); 
      newoption.text = city; 
      newoption.value = city; 
      drp2.options.add(newoption); 
      } 
   }
  </script>

============================

webform1.aspx

private void page_load(object sender, system.eventargs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!ispostback)
   {
    sqlconnection con = new sqlconnection(“packet size=4096;user id=sa;data source=server;persist security info=false;initial catalog=pubs”);
    sqldataadapter da = new sqldataadapter(“select state from authors group by state”,con);
    dataset ds = new dataset(“state”);
    da.fill(ds);
    this.dropdownlist1.datasource = ds.tables[0];
    this.dropdownlist1.datatextfield = “state”;
    this.dropdownlist1.datavaluefield = “state”; 
    this.dropdownlist1.databind();  
    this.dropdownlist1.attributes.add(“onchange”,”load()”);  
    //dropdownlist1.
   }
  
  }

webform2.aspx

 private void page_load(object sender, system.eventargs e)
  {
   // 在此处放置用户代码以初始化页面
   if(this.request[“state”]!=null)
   {  
    string state = this.request[“state”].tostring();  
    sqlconnection con = new sqlconnection(“packet size=4096;user id=sa;data source=server;persist security info=false;initial catalog=pubs”);
    sqldataadapter da = new sqldataadapter(“select address from authors where state = “+state+””,con);  
    dataset ds = new dataset(“address”);  
    da.fill(ds);  
    xmltextwriter writer = new xmltextwriter(response.outputstream, response.contentencoding);  
    writer.formatting = formatting.indented;  
    writer.indentation = 4;  
    writer.indentchar = ;  
    ds.writexml(writer);  
    writer.flush();  
    response.end();  
    writer.close();  
   }
  }

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 再谈 N 个 ASP.net DropDownList 无刷新联动菜单-.NET教程,Asp.Net开发
分享到: 更多 (0)