分开两次绑定就行了,选A就绑定A,选B就绑定B,很简单哦

解决方案 »

  1.   

    我在查询分析器中用下面的方法可以取出特定的
    select mytext from t_tree where (substring(right(parentid,2),1,1)=  4)
    ----------
    B.1
    B.2
    B.3
    B.4
    关键是那个  4  是动态的,我该怎么弄呢?
    用SqlDataReader可行吗?可行怎么弄?
      

  2.   

    A表
    select * from 表名 where parentid ='0_1_'
    B表
    select * from 表名 where parentid = @parentid @parentid传DropDownList1选择的value
      

  3.   

    参考一下:
    dropdownlist里面不是有autopostback属性吗?把它a的设为autopostback=true
    会自动提交到本页,在page_load里,根据a提交的值绑定到b,同样的方法设置b。
      

  4.   

    1.Page_Load,绑定DDL1
    if (!Page.IsPostBack)
    {
        //绑定DDL1 Sql语句:Select * from [yourTable] where parentID ='0_1_'
    }2 DDL1 AutoPostBack=true SelectedIndexChanged:
    绑定DDL2,string ddl1 =DDL1.SelectedItem.Text
    Sql语句用 "Select [text] from [yourTable] where Text<> '"+ddl1+"' and [text] like '"+ddl1+"%'"
      

  5.   

    to  acewang(大灰很) :你误会了,我是为了看清楚方便就像那样写的,其实text是没有规律的,不能用like的。
      

  6.   

    可以在第一个dropdownlist中写:
    private void DropDownListA_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    string strSQL = "select text from yourTable where text like '%"+this.DropDownListA.SelectedValue.ToString()+"%' order by nodeid";
    SqlConnection sqlConn = new  SqlConnection(strConn);
    SqlCommand sqlComm = new SqlCommand (strSQL,sqlConn);
    SqlDataReader sqlRead =  null;
    try
    {
    sqlConn.Open();
    sqlRead = sqlComm.ExecuteReader();
    while (sqlRead.Read() == true)
    {
    this.DropDownListB.Items.Add(sqlRead["text"].ToString());
    }
    }
    catch
    {
    sqlRead.Close();
    sqlConn.Close();
    }
    finally
    {
    sqlRead.Close();
    sqlConn.Close();
    } }
      

  7.   

    如果不用like你中有一个可以区别出是A还是B的条件,你把sql后的条件换一下不就可以了吗?
      

  8.   

    是A还是B是由那个nodeid来确定的,像 A.1、A.2的nodeid = 1(从他们的parentid中的1可以知道的,因为A的nodeid是1),B.1、B.2....的nodeid=4 (也可以出他们的parentid中的4知道的,因为B的nodeid是4)。
    nodeid    parentid    text
    1           0_1_      A
    2           0_1_1_    A.1 
    3           0_1_1_    A.24           0_1_      B
    5           0_1_4_    B.1
    6           0_1_4_    B.2
    7           0_1_4_    B.3
    8           0_1_4_    B.4
      

  9.   

    所以要截取那个parentid中的一个字符来和nodeid比较了。