两个 DropDownList控件,是联动菜单,想让第二个DropDownList控件点击时候触发SelectedIndexChanged事件,但是没有反应,不知道怎么回事,请指教

解决方案 »

  1.   

    这个用JS做就好了http://zxe-llh-163-com.iteye.com/blog/806029
      

  2.   

    代码如下,联动都OK了,就是第二个DropDownList里显示数据后,我想任点一个把TEXT取出来
     protected void Page_Load(object sender, EventArgs e)
        {           string sql = "select * from RTX_Dept";     
            SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ythzhConnectionString"].ConnectionString);
            SqlCommand scomm = new SqlCommand(sql, conn);
            conn.Open();
            scomm.ExecuteNonQuery();        DataTable dt = new DataTable();
            dt.Load(scomm.ExecuteReader());   
            if (!IsPostBack)  
            {
                             
                System.Data.DataView dv = dt.DefaultView;
                dv.RowFilter = "PDeptID=0";
                DropDownList1.DataSource = dv;
                DropDownList1.DataTextField = "DeptName";
                DropDownList1.DataValueField = "DeptID";
                DropDownList1.DataBind();
                System.Data.DataView dv2 = dt.DefaultView;
                dv2.RowFilter = "PDeptID=" + DropDownList1.SelectedValue;
                DropDownList2.DataSource = dv2;
                DropDownList2.DataTextField = "DeptName";
                DropDownList2.DataValueField = "PDeptID";
                DropDownList2.DataBind();          
               
            }          
        }
      
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {        string sql = "select * from RTX_Dept";
            SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ythzhConnectionString"].ConnectionString);
            SqlCommand scomm = new SqlCommand(sql, conn);
            conn.Open();
            scomm.ExecuteNonQuery();        DataTable dt = new DataTable();
            dt.Load(scomm.ExecuteReader());
            System.Data.DataView dv2 = dt.DefaultView;
            dv2.RowFilter = "PDeptID=" + DropDownList1.SelectedValue;
            DropDownList2.DataSource = dv2;
            DropDownList2.DataTextField = "DeptName";
            DropDownList2.DataValueField = "PDeptID";
            DropDownList2.DataBind();
            Session["Temp_Name1"] = DropDownList1.SelectedItem.Text;
            string Temp_Class = "select * from IP_LocalAllot where [DeptName] = '" + Session["Temp_Name1"] + "'";
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ythzhConnectionString"].ConnectionString);
            SqlCommand scom = new SqlCommand(Temp_Class, con);
            con.Open();
            scom.ExecuteNonQuery();        SqlDataReader CN;
            CN = scom.ExecuteReader();        while (CN.Read())
            {
                Label1.Text = CN["ID"].ToString();  //取出单位ID(用来赋值给PID)            
            }
            con.Close();        string T_ID = Label1.Text.Trim();   //录入数据时把T_ID赋值给数据表IP_LocalAllot里的PID
           
        }    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            // 把相对应的下级单位名称赋值给数据表IP_LocalAllot里的DeptName        Label2.Text = DropDownList2.SelectedValue;
            string T_Name = Label2.Text.Trim();  
           
        }   
      

  3.   

    检查autopostback是否为true 
      

  4.   


    DropDownList2.AutoPostBack = true;
      

  5.   

    DropDownList2.AutoPostBack = true;
    知道是这个,还是不行,不知道哪的问题