中国 美国
单击中国后会显示 
北京上海广州深圳
单击美国后会显示 
纽约华盛顿费城拉斯维家斯这些数据都是在数据库里的 
一个是country
一个是city    的
关联也做好了这个怎么做 ?

解决方案 »

  1.   

    没说明白吧,是不是中国和美国在datalist外面呢?还是嵌套在一起的
      

  2.   

    描述不清楚
    表面看,好像是个级联下拉框似的
    但你说与DataList相关,是不是点击一列或标题,然后City是在Datalist内另一列显示
    具本方式是什么
      

  3.   

    用 DropdownList 吧
    http://www.66study.com/Article/web/net/kaifa/200508/65754.html
      

  4.   

    使用父子表吧,参考:
    http://dotnet.aspx.cc/ShowDetail.aspx?id=149E5DD7-3B32-461e-ACC6-51D1652E6746
    另外往上有很多类似控件,很轻松就可以实现你的要求.
      

  5.   

    可以用无刷新的DropdownList联动实现
    参考代码
    <%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="WebApptest1.WebForm2" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
     <HEAD>
      <title>WebForm2</title>
      <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
      <meta content="C#" name="CODE_LANGUAGE">
      <meta content="JavaScript" name="vs_defaultClientScript">
      <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      <script>
          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");
           oHttpReq.open("POST", "webform6.aspx?state="+state, false);
           oHttpReq.send("");
           result = oHttpReq.responseText;
           oDoc.loadXML(result);
           items = oDoc.selectNodes("//CITY/Table");
           for (var item = items.nextNode(); item; item = items.nextNode()){
        var city = item.selectSingleNode("//city").nodeTypedValue;
        var newOption = document.createElement("OPTION");
        newOption.text = city;
        newOption.value = city;
        drp2.options.add(newOption);
           }
          }
      </script>
     </HEAD>
     <body MS_POSITIONING="flowLayout">
      <form id="Form1" method="post" runat="server">
       <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
       <asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
      </form>
     </body>
    </HTML> 
    private void Page_Load(object sender, System.EventArgs e){
      // Put user code to initialize the page here
      if(this.Request["state"]!=null){
      string state = this.Request["state"].ToString();
      SqlConnection con = new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=sa;");
      SqlDataAdapter da = new SqlDataAdapter("select city from authors where state = '"+state+"'",con);
      DataSet ds = new DataSet("CITY");
      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();
     }
    // return next node in document order
    function nextNode(node) {
        if (!node) return null;
        if (node.firstChild){
            return node.firstChild;
        } else {
            return nextWide(node);
        }
    }
    // helper function for nextNode()
    function nextWide(node) {
        if (!node) return null;
        if (node.nextSibling) {
            return node.nextSibling;
        } else {
            return nextWide(node.parentNode);
        }
    }
    // return previous node in document order
    function prevNode(node) {
        if (!node) return null;
        if (node.previousSibling) {
          return previousDeep(node.previousSibling);
        }
        return node.parentNode;
    }
    // helper function for prevNode()
    function previousDeep(node) {
        if (!node) return null;
        while (node.childNodes.length) {
            node = node.lastChild;
        }
        return node;
    }
      

  6.   

    http://www.66study.com/Article/web/net/kaifa/200508/65754.html
    用DROPLIST比较好用一些
      

  7.   

    我不想用DROPLIST
    DROPLIST 我会的
    中国 美国是DataList显示的
    北京 上海 广州 深圳
    纽约 华盛顿 费城拉 斯维加斯 也是用DataList显示的也就是说在同一个网页要两个DataList
      

  8.   

    方法笨点,但可以实现
    在国家DataList中的Item模版中加个LinkButton(ID="自己取") 隐藏并设置命令名为Edit,
    在DataList事件中双击ItemBound事件,写入
    if(e.Item.ItemIndex!=-1)
    {
        e.Item.Attributes.Add("onclick",Page.GetPostBackClientHyperlink((LinkButton)e.Item.FindControl("自己取"),""));
    }
    在DataList事件中双击Edit事件,加入你要绑定到城市DataLst的代码