dropdownlist 通过数据库绑定 我要实现(比如说:在第一个dropdownlist1 中选择“计算机软件类”在dropdownlist2相应的出现子类:软件工程师 软件测试员 价架构师等;如果在dropdownlist1选择“经营管理类”在dropdownlist2 相应出现“总监、营销经理……”等等)数据库中我设计“计算机软件类”的列名(ID)为1,相应的“软件工程师 软件测试员 价架构师”也对应为1  望各位多多指点!

解决方案 »

  1.   

    在网上搜索一下 ajax 二级联动 这种做法用ajax很流行 
      

  2.   

    自己写也可以。
    自动回送服务器,然后对应dropdownlist2的选项改变。
      

  3.   

    去51aspx有个三级城市联动的例子。你去找找吧。
      

  4.   

    最简单用服务器控件来做就是
    2个DropDownList第一个取出来,再加个隐藏域,保存第一个DropDownList取出来的值,第2个DropDownList的数据源参数从这个隐藏域取值
      

  5.   


    首先dropdownlist1 属性要设置为AutoPostBack为true
    Page_Load里
    if(!ispostback)
    dropdownlist1 绑定数据库,可以设置显示默认计算机软件类.
    dropdownlist2  绑定数据库,设置显示默认计算机软件类下的各项
    DataTextField="计算机软件类";//显示在页面的值;
    DataValueField="ID";//实际的值; 在dropdownlist1 的选择项改变时,触发DropDownList1_SelectedIndexChanged,主要代码如下:
    根据string text=DropDownList1.SelectedValue的值,在数据库中匹配,重新绑定dropdownlist2
        
      

  6.   

    是否刷新?
    刷新就设dropdownlist1的属性 AutoPostBack="true"然后在dropdownlist1的OnSelectedIndexChanged="dropdownlist1_SelectedIndexChanged"事件里根据dropdownlist1.SelectValue查询数据绑定dropdownlist2
    无刷新从网上搜吧,有很多
      

  7.   

    我这里有一个demo。在你的网站(创建时是ajax enabled的)创建一个aspx页面,然后把下面内容覆盖到上面测试:<%@ Page Language="C#" inherits="VPage" %><script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Calendar1.Style["position"] = "absolute";
                this.TextBox1.DataBind();
            }
        }    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DropDownList2.Items.Clear();
            switch (this.DropDownList1.SelectedValue)
            {
                case "北京":
                    this.DropDownList2.Items.Add("天安门广场");
                    this.DropDownList2.Items.Add("颐和园");
                    this.DropDownList2.Items.Add("雍和宫");
                    this.DropDownList2.Items.Add("红螺寺");
                    break;
                case "上海":
                    this.DropDownList2.Items.Add("崇明岛");
                    this.DropDownList2.Items.Add("外滩");
                    this.DropDownList2.Items.Add("万佛阁");
                    break;
                case "香港":
                    this.DropDownList2.Items.Add("海洋公园");
                    this.DropDownList2.Items.Add("半岛酒店");
                    break;
            }
        }
        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ShowResult();
        }    protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Calendar1.SelectedDate = DateTime.Parse(this.TextBox1.Text);
            }
            catch
            {
            }
            this.Calendar1.Visible = true;
        }    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            this.TextBox1.Text = this.Calendar1.SelectedDate.ToShortDateString();
            this.Calendar1.Visible = false;
            ShowResult();
        }    void ShowResult()
        {
            this.Label1.Text = "您选择" + this.TextBox1.Text + "去" + this.DropDownList2.SelectedValue;
            UpdatePanel3.Update();
        }
    </script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>在开发ajax应用初期使用基本的asp.net ajax功能,避免那种奢谈一大堆javascript的做法</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem>北京</asp:ListItem>
                    <asp:ListItem>上海</asp:ListItem>
                    <asp:ListItem>香港</asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    请输入日期:
                </td>
                <td>
                    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <table cellpadding="0" cellspacing="0">
                                <tr>
                                    <td>
                                        <asp:TextBox ID="TextBox1" runat="server" Width="147px" Text="<%# DateTime.Now.AddDays(20).ToShortDateString() %>" />
                                        <asp:Button ID="Button1" runat="server" Text="..." OnClick="Button1_Click" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Calendar ID="Calendar1" runat="server" Visible="False" OnSelectionChanged="Calendar1_SelectionChanged"
                                            BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
                                            Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" ShowGridLines="True"
                                            Width="220px">
                                            <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
                                            <SelectorStyle BackColor="#FFCC66" />
                                            <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
                                            <OtherMonthDayStyle ForeColor="#CC9966" />
                                            <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
                                            <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
                                            <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
                                        </asp:Calendar>
                                    </td>
                                </tr>
                            </table>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
        </table>
        <hr />
        <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                result:
                <asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Size="Small"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
        </form>
    </body>
    </html>
      

  8.   

                其实像这样的联动 如果在服务端获取很浪费资源 可以考虑要javascript的数组