不刷新dropdownlist聯動

js:
<script type="text/javascript">
//<![CDATA[
    function fLoadXml(url, show){
    
var drp1 = document.getElementById("DropDownList1");
    
var ClassID=drp1.options[drp1.selectedIndex].value;
    
    
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
  
var oDoc = new ActiveXObject("microsoft.xmldom");
  oHttpReq.open(
"POST""no_refresh2.aspx?ClassID="+ClassID, false); 
  
//
  //调用读取小类数据的页面,将大类
  // 编号值传递过去
  oHttpReq.send("");
  
//result = oHttpReq.responseText;
  
        
switch(fCkDom2()){
            
case 1:
                
var xml=document.implementation.createDocument('','',null);
                    xml.onload 
= function(){show(xml, url);}
                    xml.load(url);
                
break;
            
case 2
                
var xml=new ActiveXObject('microsoft.xmldom');
                    xml.onreadystatechange
=function(){
                        
if(xml.readyState==4){
                            show(xml, url);
                        }

                    }
 
                    xml.load(url);
                
break;
            
default: document.write('unknown');
        }

        
        
function fCkDom2(){
            
if(document.implementation&&document.implementation.createDocument)return 1;
            
else if(window.ActiveXObject) return 2;
            
else return 0;
        }

    }

    
    
function fShowXml(xml, url){
    
var drp2 = document.getElementById("DropDownList2");
    
//alert(drp2);
  function RemoveAll(oElem) //清除DropDownList2的所有项
  var i = 0;
  
for (i = oElem.length; i >= 0; i--){
  oElem.options.remove(i);
  }

  }

  RemoveAll(drp2);
  
//将小类的类名和编号赋予DropDownList2
//
alert(content);
    var tOption = document.createElement("OPTION");
    tOption.text
="請選擇";
    
// alert(newOption.text);
    tOption.value="請選擇";
   
//alert(newOption.value);
   drp2.options.add(tOption);
  
        
//alert('ok');
        var elements=xml.getElementsByTagName('Table');
            
for(var i=0; i<elements.length; i++){
                
                
for(var j=0; j<elements[i].childNodes.length; j++){
                    
if(elements[i].childNodes[j].nodeType==1){
                        
var eSub=elements[i].childNodes[j]
                    
                        
var content;
            
                            
try{
                                content
=eSub.firstChild.data;//.fontcolor('blue');
                            }
 catch(e){
                                content
='empty';
                            }

                    
                    
//将小类的类名和编号赋予DropDownList2
                    //alert(content);
                     var newOption = document.createElement("OPTION");
                      newOption.text
=content;
                     
// alert(newOption.text);
                      newOption.value=content;
                      
//alert(newOption.value);
                      drp2.options.add(newOption);
                    }

                }
  
            }

    }

//]]>onload="fLoadXml('xml.xml', fShowXml);"onload="fLoadXml('xml.xml', fShowXml);"
</script>


主頁code:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   If Not Page.IsPostBack Then
            Dim myda As System.Data.SqlClient.SqlDataAdapter
            Dim ds As System.Data.DataSet
  sqlcomm("goods_tree")'調用存儲過程
            Dropdownlist_Bind(Me.DropDownList1, mycomm, "0", "2")‘綁定
            '"javascript:document.Form1.TH.value=this.options[this.selectedIndex].value;");
            Me.DropDownList1.Attributes.Add("onchange", "fLoadXml('xml.xml', fShowXml);")’調用事件
  End If

調用數據html:
Imports System.Xml
Imports System.IO

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Dim myda As System.Data.SqlClient.SqlDataAdapter
        Dim ds As System.Data.DataSet
        ' Request.QueryString("ClassID") = "2"
        If (Me.Request.QueryString("ClassID") <> Nothing) Then
            Dim state As String = Me.Request.QueryString("ClassID").ToString()
            Try
                '綁定市

                sqlcomm("goods_select_code")
                ' SELECT distinct CountryRegion,StateProvince
                'from Geography
                With mycomm
                    .Parameters.AddWithValue("@Goods_ID", state.Trim) 'state.Trim
                End With
                myda = New System.Data.SqlClient.SqlDataAdapter(mycomm)
                ds = New Data.DataSet("pro")
                ds.Tables.Clear()
                sqlconn_Open()
                myda.Fill(ds)
                sqlconn_Close()
                '   ds.WriteXml("xml.xml", XmlWriteMode.WriteSchema)
                ds.WriteXml(Server.MapPath("xml.xml"))
            Catch ex As Exception

            End Try

        End If


    End Sub

posted @ 2006-11-20 11:06  Nina  阅读(403)  评论(0编辑  收藏  举报