我写了2个dropdownlist,在选取第一个dropdownlist1的值(从数据库中加载)后我要在dropdownlist2中动态添加从数据库中选取的和dropdownlist的值对应的另一个字段的值,给如何获取啊?我试写了代码,可是不能得到,以下是我写的,请指点:      
                                                                           
SqlConnection    sqlstr1    =    new    SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);      
   
                                                                     SqlDataAdapter    myda1    =    new    SqlDataAdapter("select    Student_Name    from    Student_Info    where    Student_Id='"+    this.DropDownList1.SelectedItem.Text.Trim().ToString()    +"'",sqlstr1);      
                                                                     DataSet    ds1    =    new    DataSet();      
                                                                     myda1.Fill(ds1);      
                                                                     string    s=?;      
                                                                     this.DropDownList2.Items.Add(new    ListItem(?));      
   
怎么样处理‘?’处啊?

解决方案 »

  1.   

    this.Dropdownlist.datasource=myda1.read();
    this.Dropdownlist.Databind();
      

  2.   

    前几点意见:
    1.dropdownlist1的autopostback属性有没设置为true.
    2.dropdownlist1的selectedindexchanged事件中有没有加载dropdownlist2
      

  3.   

    to littlebeer(小啤酒)第一点我知道的,已经做好了的,第二点我就不明白了,还有就是我是想 在选取了dropdownlist1之后根据dropdownlist1 的取值在数据库 里面取出对应的字段值放到dropdownlist2中,那应该如何操作呢?
      

  4.   

    你可以在selectedindexchanged事件中写一段代码,就是先获得dropdownlist1.selectedvalue的值,然后像你上面一样,绑定第二个dropdownlist,指定其dropdownlist2.datasource;
    dropdownlist2.DataValueField
    和dropdownlist2.DatatextField
    最后dropdownlist2.databind
      

  5.   

    第一个dropdownlist1的autopostback属性设置为true.
    并且设置事件SelectedIndexChanged
    在后台事件里,取出该下拉框值
    private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    string myKeyid = this.DropDownList1.SelectedValue;
    string sql = "select 字段1,字段2 from 表 where id = '" + myKeyid + "' ";
    //通过SQL语句取得数据集
    this.DropDownList2.DataSource = 数据集;
    this.DropDownList2.DataValueField = 字段1名称;
    this.DropDownList2.DataTextField = 字段2名称;
    this.DropDownList2.DataBind();}
      

  6.   

    //通过SQL语句取得数据集
    取得数据集的过程要自己写,不要忘记了
      

  7.   

    谢谢几位,还有个问题
    this.DropDownList2.DataValueField = 字段1名称;
    this.DropDownList2.DataTextField = 字段2名称;
    这两句话我不是很明白,为什么都是dropdownlist2的属性,取得的字段名为什么不一样?到底是怎样的?
      

  8.   

    第一个参数表示你要将此下拉框的value值绑定到哪个字段
    第二个表示将显示出来的值绑定到哪个字段
    要注意是文本,要用双绰号括起来.