| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 619 人关注过本帖
标题:请问如何实现dropdownlist的三级联动?
只看楼主 加入收藏
hellenism
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2009-2-27
结帖率:76.47%
收藏
已结贴  问题点数:20 回复次数:1 
请问如何实现dropdownlist的三级联动?
最近在自学 自己做一个小项目玩玩,用到dropdownlist的三级联动,不知道如何实现,请各位指点,谢谢!
代码:
目的是从一张表中选出 "学院" 填充dropdownlist1,然后根据dropdownlist1的选择 从表中选出 "专业"填充dropdownlist2,再根据dropdownlist2的选择,从表中选出"班级" 填充dropdownlist3,但是好像每次回传之后dropdownlist1都是一样的,导致dropdownlist2也是一样..
protected void Page_Load(object sender, EventArgs e)
    {
            string strCon = "Data Source=.;" +
                                  "Initial Catalog=studentManageSystem;" +
                                  "Integrated Security=True;";

            string strSQL = "select distinct academyName from academyCourse";

            SqlConnection con = new SqlConnection(strCon);

            con.Open();

            SqlDataAdapter da = new SqlDataAdapter(strSQL, con);

            DataSet ds = new DataSet();

            da.Fill(ds);

            DropDownList1.DataSource = ds.Tables[0];
            DropDownList1.DataValueField = "academyName";
            DropDownList1.DataTextField = "academyName";
            DropDownList1.DataBind();//触发绑定事件

            con.Close();
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
            string strCon ="Data Source=.;" +
                                  "Initial Catalog=studentManageSystem;" +
                                  "Integrated Security=True;";

            string strSQL = string.Format("select distinct academyprofession from academyCourse where academyName='{0}'", DropDownList1.SelectedValue.ToString().Trim());

            SqlConnection con = new SqlConnection(strCon);

            con.Open();

            SqlDataAdapter da = new SqlDataAdapter(strSQL, con);

            DataSet ds = new DataSet();

            da.Fill(ds);

            DropDownList2.DataSource = ds.Tables[0];
            DropDownList2.DataValueField = "academyprofession";
            DropDownList2.DataTextField = "academyprofession";
            DropDownList2.DataBind();//触发绑定事件

            con.Close();
        
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        
            string strCon ="Data Source=.;" +
                                  "Initial Catalog=studentManageSystem;" +
                                  "Integrated Security=True;";

            string strSQL = string.Format("select distinct classes from academyCourse where academyprofession='{0}'", DropDownList2.SelectedValue.ToString().Trim());

            SqlConnection con = new SqlConnection(strCon);

            con.Open();

            SqlDataAdapter da = new SqlDataAdapter(strSQL, con);

            DataSet ds = new DataSet();

            da.Fill(ds);

            DropDownList3.DataSource = ds.Tables[0];
            DropDownList3.DataValueField = "classes";
            DropDownList3.DataTextField = "classes";
            DropDownList3.DataBind();//触发绑定事件

            con.Close();
搜索更多相关主题的帖子: dropdownlist 
2010-05-27 16:09
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:20 
Page_Load中加IsPostBack

飘过~~
2010-05-27 16:42
快速回复:请问如何实现dropdownlist的三级联动?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051729 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved