• 无刷新汽车品牌三级联动


                                                    无刷新汽车品牌三级联动
             default.aspx:

    <table class="wz" cellSpacing="0" cellPadding="0" width="100%" border="0">
                                    
    <tr>
                                        
    <td colSpan="4"><asp:textbox id="txtbrandcountry" Runat="server" Text="国内" Width="0"></asp:textbox><asp:textbox id="txtpp" Runat="server" Text="0" Width="0"></asp:textbox><asp:textbox id="txtcx" Runat="server" Text="0" Width="0"></asp:textbox><input onclick="XmlPost1(0)" type="radio" CHECKED name="brandCountry"><b>国产</b>&nbsp;
                                            
    <input onclick="XmlPost1(1)" type="radio" name="brandCountry"><b>进口</b></td>
                                    
    </tr>
                                    
    <tr>
                                        
    <td align="right" width="50">品 牌:</td>
                                        
    <td align="left"><asp:dropdownlist id="DropDownList1" runat="server"></asp:dropdownlist><asp:textbox id="txtppname" Runat="server" Width="0px" CssClass="ff"></asp:textbox></td>
                                        
    <td align="right" width="50">车 型:</td>
                                        
    <td align="left"><asp:dropdownlist id="DropDownList2" runat="server"></asp:dropdownlist><asp:textbox id="txtcxname" Runat="server" Width="0px" CssClass="ff"></asp:textbox></td>
                                    
    </tr>                                <tr>
                                        
    <td align="left" colSpan="4"><font color="red">&nbsp;当前车型为:
                                                
    <div id="pjname"></div>
                                            
    </font>
                                        
    </td>
                                    
    </tr>
    </table>

    <SCRIPT language="JavaScript">
                
    <!--
                    
    //以XML求取DropDownList2的数据
                    function XmlPost2(obj)
                    {
                      
    var svalue = obj.value;
                      
    var webFileUrl = "?carid=" + svalue;
                      
    var result = "";
                      
    var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                      xmlHttp.open(
    "POST", webFileUrl, false);
                      xmlHttp.send(
    "");
                      result 
    = xmlHttp.responseText;
                      
                      
    if(result != "")
                      {
                          
    var drop2=document.getElementById("DropDownList2");
                        drop2.length
    =0;
                        drop2.visible
    =true;
                        
    var piArray = result.split(",");
                        
    for(var i=0;i<piArray.length;i++)
                        {
                          
    var ary1 = piArray[i].toString().split("|");
                          document.all(
    "DropDownList2").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
                        }
                        document.all(
    "txtpp").value=document.all("DropDownList1").value;
                        document.all(
    "txtcx").value=document.all("DropDownList2").value;
                        document.all(
    "txtppname").value  = document.getElementById("DropDownList1").options[document.getElementById("DropDownList1").selectedIndex].text;
                        document.all(
    "txtcxname").value  = document.getElementById("DropDownList2").options[document.getElementById("DropDownList2").selectedIndex].text;
                        getpjstr();
                        
                        
                      }
                      
    else
                      {
                        alert(result);
                      }
                    }
                    
                    
    function setchexing()
                    {
                     
                     document.all(
    "txtcx").value=document.all("DropDownList2").value;
                     document.all(
    "txtcxname").value  = document.getElementById("DropDownList2").options[document.getElementById("DropDownList2").selectedIndex].text;
                     getpjstr();
                    }
                    
    function setchexing2()
                    {
                      
    //alert("txtcx"+document.all("txtcx").value);
                     if(document.all("txtcx").value!=""&&document.all("txtcx").value!="0")
                     {
                        document.all(
    "DropDownList2").value=document.all("txtcx").value;
                     }
                    }
                    
    function getpjstr()
                    {
                     
                      document.getElementById('pjname').innerHTML 
    = "&nbsp;&nbsp;"+document.all("txtbrandcountry").value;
                      
    if(document.all("txtppname").value!="选择品牌..")
                      document.getElementById('pjname').innerHTML 
    +="--&gt;"+document.all("txtppname").value;
                      
    if(document.all("txtcxname").value!="选择系列..")
                      document.getElementById('pjname').innerHTML 
    +="--&gt;"+document.all("txtcxname").value;
                      
                      
                    }
                    
    function XmlPost1(svalue)
                    {
                      
    //var svalue = obj.value;
                      if(svalue==0)
                        {
                         document.all(
    "txtbrandcountry").value="国内";
                      }
                      
    else
                      {
                        document.all(
    "txtbrandcountry").value="进口";
                      }
                      document.all(
    "txtppname").value="选择品牌.."
                      document.all(
    "txtcxname").value="选择系列.."
                      getpjstr();
                      
                      
                      
                      
    var webFileUrl = "?brandCountry=" + svalue;
                      
    var result = "";
                      
    var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                      xmlHttp.open(
    "POST", webFileUrl, false);
                      xmlHttp.send(
    "");
                      result 
    = xmlHttp.responseText;
                      
                      
    if(result != "")
                      {
                        document.all(
    "DropDownList1").length=0;
                        document.all(
    "DropDownList2").length=0;
                        document.all(
    "DropDownList1").options.add(new Option("选择品牌..",""));
                        document.all(
    "DropDownList2").options.add(new Option("选择系列..",""));
                        
    var piArray = result.split(",");
                        
    for(var i=0;i<piArray.length;i++)
                        {
                          
    var ary1 = piArray[i].toString().split("|");
                          document.all(
    "DropDownList1").options.add(new Option(ary1[1].toString(),ary1[0].toString()));
                        }
                      }
                      
    else
                      {
                        alert(result);
                      }
                    }
                    
                
    //-->
                </SCRIPT>
    default.cs:

    private void Page_Load(object sender, System.EventArgs e)
            {
                
    if(!this.IsPostBack)
              {
                
    this.down1_bind("0");//帮定国产车型
                    this.DropDownList1.Attributes.Add("onchange","XmlPost2(this);");
                    
    this.DropDownList2.Attributes.Add("onchange","setchexing();");
                    
              }
              
    if(carid != "")
              {
                  
    //如果品牌不为空时,帮定车型
                this.down2_bind(carid);
              }
                
    if(brandCountry != ""&& brandCountry!="on")
              {
                    
    //帮定国内或进口车型
                this.down3_bind(brandCountry);
                    
              }

                
            }
            
    #region down2_bind
                
    private void down2_bind(string id)
                {
              
    string mystr = "";
                
    string sql="select csmallid,classname from Base_ProdClass where cbigid='"+id+"' and NamePY is null order by classname";
              DataSet ds 
    = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING,CommandType.Text,sql);

              
    if(ds.Tables[0].Rows.Count != 0)
              {
                
    for(int i=0;i<ds.Tables[0].Rows.Count;i++)
                {
                  mystr 
    += "," + ds.Tables[0].Rows[i][0].ToString() + "|" + ds.Tables[0].Rows[i][1].ToString();
                        
                }
                mystr 
    = mystr.Substring(1);
              }
              
    this.Response.Write(mystr);
              
    this.Response.End();
                }
            
    private void down22_bind(string id)
            {
              
    string mystr = "";
                
    string sql="select csmallid,classname from Base_ProdClass where cbigid='"+id+"' and NamePY is null order by classname";
              DataSet ds 
    = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING,CommandType.Text,sql);
                
    this.DropDownList2.DataValueField = "csmallid";
              
    this.DropDownList2.DataTextField = "classname";
              
    this.DropDownList2.DataBind(); 
                DropDownList2.Items.Insert(
    0,new ListItem("选择系列..",String.Empty));   
                DropDownList2.SelectedIndex 
    = DropDownList2.Items.IndexOf(DropDownList2.Items.FindByValue(this.txtcx.Text));

             
            }
            
            
    #endregion

            
    #region carid
                
    private string carid
                {
                    
    get
                    {
                        
    if(ViewState["carid"]!=null && ViewState["carid"].ToString()!="")
                        {
                            
    return ViewState["carid"].ToString();
                        }
                        
    else
                        {
                            
    if(Request["carid"]!=null && Request["carid"].ToString()!="")
                            {
                                
    return Request["carid"];
                            }
                            
    else
                            {
                                
    return "";
                            }
                        }
                    }
                    
    set
                    {
                        ViewState[
    "carid"]=value;
                    }
                }

            
            
    #endregion
            
            
    #region brandCountry
            
    private string brandCountry
            {
                
    get
                {
                    
    if(ViewState["brandCountry"]!=null && ViewState["brandCountry"].ToString()!="")
                    {
                        
    return ViewState["brandCountry"].ToString();
                    }
                    
    else
                    {
                        
    if(Request["brandCountry"]!=null && Request["brandCountry"].ToString()!="")
                        {
                            
    return Request["brandCountry"];
                        }
                        
    else
                        {
                            
    return "";
                        }
                    }
                }
                
    set
                {
                    ViewState[
    "brandCountry"]=value;
                }
            }

            
            
    #endregion


            
    #region down1_bind
                
    private void down1_bind(string country)
                {
             
                
              DataSet ds 
    =SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING,CommandType.Text,"select cbigid,classname from Base_ProdClass where NamePY='"+country+"' order by classname");
              
    this.DropDownList1.DataSource = ds;
              
    this.DropDownList1.DataValueField = "cbigid";
              
    this.DropDownList1.DataTextField = "classname";
              
    this.DropDownList1.DataBind(); 
                DropDownList1.Items.Insert(
    0,new ListItem("选择品牌..",String.Empty));
                DropDownList2.Items.Insert(
    0,new ListItem("选择系列..",String.Empty));         
                }
            
    private void down3_bind(string id)
            {
            
                
    string mystr = "";
                
    string sql="select cbigid,classname from Base_ProdClass where NamePY='"+id+"' order by classname";
              DataSet ds 
    = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING,CommandType.Text,sql);

              
    if(ds.Tables[0].Rows.Count != 0)
              {
                
    for(int i=0;i<ds.Tables[0].Rows.Count;i++)
                {
                  mystr 
    += "," + ds.Tables[0].Rows[i][0].ToString() + "|" + ds.Tables[0].Rows[i][1].ToString();
                }
                mystr 
    = mystr.Substring(1);
              }
              
    this.Response.Write(mystr);
              
    this.Response.End();         
            }
            
    #endregion

    sql:

    CREATE TABLE [dbo].[Base_ProdClass] (
        
    [CBigID] [varchar] (4) COLLATE Chinese_PRC_CI_AS NOT NULL ,
        
    [CSmallID] [varchar] (2) COLLATE Chinese_PRC_CI_AS NULL ,
        
    [ClassName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
        
    [NamePY] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL 
    ON [PRIMARY]
    GO

    数据库下载,此车型库为11月29日更新

  • 相关阅读:
    求秋名山老司机车速
    JSON详解
    mysql 建立索引的原则
    mysql 建立索引的原则
    jQuery的html(),text()和val()比较
    jQuery的html(),text()和val()比较
    CSS cursor 属性
    CSS cursor 属性
    判断是否为润年
    mysql 查看当前使用的配置文件my.cnf的方法
  • 原文地址:https://www.cnblogs.com/jasonduan/p/577780.html
Copyright © 2020-2023  润新知