用户选择了下拉框中的一个文本,我想获取这个文本怎么办?
有人帮偶解决一下吗?
我用的strsy=DropDownList1.SelectedItem.text但只能获取第一条数据而不是用户选择的数据~~~
SOS~~~555

解决方案 »

  1.   

    你是不是动态绑定了数据?
    把动态绑定的数据放在
    if(!Page.IsPostBack)
    {
    }
      

  2.   

    我把动态绑定的数据放在
    if(!Page.IsPostBack)
    {
    }
    中了结果strsy=DropDownList1.SelectedItem.Text就出错误!
    未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 82:  string strcaption=TextBox1.Text;
    行 83:  string strexplain=Textbox2.Text;
    行 84:  string strsy=DropDownList1.SelectedItem.Text; 
      

  3.   

    把AutoPostBack设置成True看看~~~没用过~~怎么设~~
      

  4.   

    把AutoPostBack设置成True看看
    不行啊~~~
      

  5.   

    他的属性啊。你点DropDownList,然后在右边的属性表里,把他的AutoPostBack属性设置为True啊
      

  6.   

    数据绑定:
    movielb.DataSource = mydata;
    movielb.DataTextField = "name";
    movielb.DataValueField = "code";
    movielb.DataBind();在下拉列表框的SelectedIndexChanged事件写代码,并把下拉列表框的AutoPostBack设为True
    string movie = movielb.SelectedItem.Text;
      

  7.   

    我绑定数据是这样的
    adapter.Fill(ds,"forum_1");
    if(DropDownList1.Items.Count == 0)
    {
    for(int i=0;i<ds.Tables[0].Rows.Count;i++)
    {
    DropDownList1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
    }
    }
      

  8.   

    倒,哪有人象你那样拌定数据的,我晕。。看看我的    Sub ddlbind()
            conn = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("shujuku"))
            cmd = New SqlClient.SqlCommand("select classid,classname from hkbbs_class", conn)
            conn.Open()
            rs = cmd.ExecuteReader
            ddl1.DataSource = rs
            ddl1.DataTextField = "classname"
            ddl1.DataValueField = "classid"
            ddl1.DataBind()
            rs.Close()
            cmd.Dispose()
            conn.Close()
        End Sub
      

  9.   

    你那样是错的。        ddl1.DataTextField = "classname"   ‘这个是指拌定你的DROPDOWNLIST的显示的文本
            ddl1.DataValueField = "classid"     ’这个是对应的值
      

  10.   

    未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 82:  string strcaption=TextBox1.Text;
    行 83:  string strexplain=Textbox2.Text;
    行 84:  string strsy=DropDownList1.SelectedItem.Text;
      

  11.   

    在Page_Load事件中:'1. 填充数据:
        DropDownList1.....'2. 绑定数据
    if  not Page.IsPostBack then
        DropDownList1.DataBind()
    end if' 3. 在DropDownList1的SelectedIndexChanged事件中得到你要的东西:
        strsy=DropDownList1.SelectedItem.Text
      

  12.   

    你试一下这个语句
    strsy=DropDownList1.Item(DROPDOWNLIST1.SELECTINDEX).text
      

  13.   

    为什么加了
    if(!IsPostBack)
    {
    }
    就会出现错误?