Web页面中有两个DropdownList,第二个DropdownList的内容是通过第一个DropdownList列表的内容决定的,这两个下拉列表的内容都是通过绑定到一个DataTable得到的.比如说DataTable是一个班级信息表,有年级,班级两个字段,一年级有3个班,二年级有2个班,当我选择一年级(第一个DropdownList的内容)的时候,第二个DropdownList只显示1班,2办,3班信息,如果选择二年级时只显示1班,2班,请高人指点

解决方案 »

  1.   

    Page_load
    先从数据库取出班级,填充到D1中,
    D1的SelectedChanged
    取出班,where 年级=D1.SelectedItem.Text
      

  2.   

    http://www.cnblogs.com/singlepine/archive/2005/10/31/265678.html小山博客中有几篇相关文章,可以参考
      

  3.   

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlConnection conn = new SqlConnection("server=192.168.2.3;database=example;uid=sa;pwd=imd2006");
                conn.Open();
                SqlDataAdapter sda = new SqlDataAdapter("select distinct classid from class order by classid", conn);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                sda.Fill(ds);
                DropDownList1.DataSource = ds.Tables[0].DefaultView;            DropDownList1.DataTextField = "classid";
                DropDownList1.DataBind();
                DropDownList1.Items.Insert(0, "Please select on class");            
                
            }
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
    SqlConnection conn = new SqlConnection("server=192.168.2.3;database=example;uid=sa;pwd=imd2006");
                conn.Open();
                SqlDataAdapter sda = new SqlDataAdapter("select distinct student from class where classid= '"+DropDownList1.SelectedItem.Text+"'", conn);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                sda.Fill(ds);
                DropDownList2.DataSource = ds.Tables[0].DefaultView;
                DropDownList2.DataTextField = "student";
                DropDownList2.DataBind();
        }注意:Dropdownlist1的enbalepostback设为true
      

  4.   

    可以借助ajax实现
    -------------------------lz并为说明需要无刷新
      

  5.   

    这样的问题觉得还是ajax好一点.
      

  6.   

    使用ajax
    http://www.i2key.com/TechDoc/Doc-1-39076.aspx
      

  7.   

    js比较强的话就用ajax
    要不就用Teng_s2000() 的方法
    或者微软的Atlas技术也可以
    不过还不完善