我想实现的多级联动好像跟网上查到的一些还不太一样。
     不是类似于省,市,县的那种联动
     是类似于电脑配件选择的联动,也就是说,第一项不但只影响第二项,也会对第三项产生影响
     这三项不存在主次关系。每一项都会影响到其他的项,也就是类似于选配电脑时,各个配件之间的关系。
     请问这样的多级联动该如何实现。

解决方案 »

  1.   

    area.aspx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="area.ascx.cs" Inherits="Global_area" %>
    <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdateProduct" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="province" runat="server" AutoPostBack="True" OnSelectedIndexChanged="province_SelectedIndexChanged" style="border:1px solid #D1D1D1;">
                    <asp:ListItem></asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="city" runat="server" AutoPostBack="True" OnSelectedIndexChanged="city_SelectedIndexChanged" style="border:1px solid #D1D1D1;">
                    <asp:ListItem></asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="area" runat="server" style="border:1px solid #D1D1D1;">
                    <asp:ListItem></asp:ListItem>
                </asp:DropDownList>
        </ContentTemplate>
    </asp:UpdatePanel>area.aspx.csusing System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Text;
    using BLL.Common;
    using System.IO;
    public partial class Global_area : System.Web.UI.UserControl
    {
        private string provinceid = "110000";
        private string cityid = "0";
        private string areaid = "0";    public string Provinceid
        {
            get { return provinceid; }
            set { provinceid = value; }
        }
        public string Cityid
        {
            get { return cityid; }
            set { cityid = value; }
        }
        public string Areaid
        {
            get { return areaid; }
            set { areaid = value; }
        }
        public string getprivincevalue()
        {
            return this.province.SelectedValue;
        }
        public string getcityvalue()
        {
            return this.city.SelectedValue;
        }
        public string getareavalue()
        {
            return this.area.SelectedValue;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindprovince(provinceid);           
                bindcity(province.SelectedValue,cityid);
                bindarea(city.SelectedValue, areaid);
            }
        }
        public void province_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindcity(province.SelectedValue, cityid);
            bindarea(city.SelectedValue, areaid);
        }
        public void bindprovince(string provinceid)
        {
            //初始化省
            DataTable dt = PublicFunc.iniprovince();
            province.DataSource = dt;
            province.DataTextField = "province";
            province.DataValueField = "provinceid";
            province.DataBind();       
            foreach(ListItem li in province.Items)
            {
                if(li.Value==provinceid)
                {li.Selected=true;}
            }
        }
        public void bindcity(string provinceid, string cityid)
        {
             //初始化市
            string sql = "select * from city where father="+provinceid;
            string filepath = AppSetting.UpLoadPath + "/city";
            if (!Directory.Exists(Server.MapPath(filepath)))
            {
                BLL.Common.Helper.FolderUtility.CreateFolder(Server.MapPath(filepath));
            }
            string filename = Server.MapPath(filepath + "/city_"+provinceid+".xml");
            DataSet ds = new DataSet();        if (File.Exists(filename))
            {
                ds.ReadXml(filename, XmlReadMode.ReadSchema);        }
            else
            {
                ds = SqlHelper.ExecuteDataset(AppSetting.ConnStr, CommandType.Text, sql);            ds.WriteXml(filename, XmlWriteMode.WriteSchema);
            }        
            city.DataSource = ds.Tables[0];
            city.DataTextField = "city";
            city.DataValueField = "cityid";
            city.DataBind();
            city.Items.Insert(0, new ListItem("--不限--", "0"));
            foreach (ListItem li in city.Items)
            {
                if (li.Value == cityid)
                { li.Selected = true; }
            }
        }    public void bindarea(string cityid,string areaid)
        {
            //初始化市
            string sql = "select * from area where father=" + cityid;
            string filepath = AppSetting.UpLoadPath + "/city";
            if (!Directory.Exists(Server.MapPath(filepath)))
            {
                BLL.Common.Helper.FolderUtility.CreateFolder(Server.MapPath(filepath));
            }
            string filename = Server.MapPath(filepath + "/area_" + cityid + ".xml");
            DataSet ds = new DataSet();        if (File.Exists(filename))
            {
                ds.ReadXml(filename, XmlReadMode.ReadSchema);        }
            else
            {
                ds = SqlHelper.ExecuteDataset(AppSetting.ConnStr, CommandType.Text, sql);            ds.WriteXml(filename, XmlWriteMode.WriteSchema);
            }
            
            area.DataSource = ds.Tables[0];
            area.DataTextField = "area";
            area.DataValueField = "areaid";
            area.DataBind();
            area.Items.Insert(0, new ListItem("--不限--", "0"));
            foreach (ListItem li in area.Items)
            {
                if (li.Value == areaid)
                { li.Selected = true; }
            }        
        }    public void city_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindarea(city.SelectedValue, areaid);
        }}
      

  2.   

    google:ajaxToolkit Cascadingdropdown控件
    http://www.google.cn/search?client=pub-5434506002917399&prog=aff&channel=2000052003&q=ajaxToolkit%20Cascadingdropdown
      

  3.   

    不用AJAX的话还不简单,每个drowplist设个autopostback=true,然后处理事件的时候重置datasource的selectcommand(就是重写查询语句)然后重新绑定就行了。等ajax达人...
      

  4.   

    可以做成单独的用户控件,做成个单独的页面更好,那样每次postback的时候数据传输量就少多了,然后用session传递用户选择的项value
      

  5.   

    类似 http://mall.cngba.com/ 里面的产品专区?
      

  6.   

    这无非就是在selectIndexChange里面实现知道了这个思路,你想改变哪个就是在触发事件的时候重新给数据源而已
      

  7.   


    晕哦,怎么实现都可以啊。只要你能用 select 语句把你每个 dl里想要的列表显示出来都行
    我给你假设三种数据
    1. WD台式机1T硬盘,
    2. Intel CoreDual2 3.2G CPU
    3. kingstone 笔记本2G DDR2 800 内存那么这类数据是有层次的,其实还是级联,两层关系
    电脑--台式机--cpu,硬盘,内存,主板,显卡
        |--笔记本--cpu,硬盘,内存,主板,显卡
    cpu,硬盘,内存,主板,显卡可以抽象出来,但要加一个属性(字段加以区分)比如 is_notebook
    用于处理那些独特的数据比如笔记本上特有的配件
    这样分来就需要两个及以上的表。
    我主张分三个表
    1 Fenlei(分类) 2 Leibie(类别) 3 Jilu(记录)
    表1的内容 
    id 1
    name 台式机
    ...
    表2
    id 1
    name 硬盘
    list 1
    is_notebook NULL
    ...
    id n
    name 笔记本触摸板
    list n
    is_notebook True表3
    id 1
    name WD台式机1T硬盘
    Fenlei_id 1
    Leibie_id 1
    neirong 内容当如果选择了笔记本 那么select不需要限制条件 如果选了台式机那么要加 select * from leibie where is_notebook <> 'True'...我也是闲的慌Orz