我需要在一个按纽的ON_CLICK代码里得到页面上的一个下拉列表的选择值。但编译时却告诉我下拉列表没有在这个类里面定义。该如何处理啊。

解决方案 »

  1.   

    cs文件中没有声明该控件 
    eg:
    namespace{
    calss{
    protected System.Web.UI.WebControls.ListBox lst_city;
    ....meghod
    }
    }
      

  2.   

    protected void Button1_Click(object sender, EventArgs e)
        {
            
            
            SqlConnection conn = new SqlConnection("Data Source=0E8403DB495C4FA;Initial Catalog=jpzxps;Integrated Security=True");
            string insertdep="INSERT INTO st2(mmm, sid) VALUES (@mmm,@sid)";
           SqlCommand comm = new SqlCommand(insertdep, conn);
           comm.CommandType = CommandType.Text;
           SqlParameter parm1 = new SqlParameter("@mmm", SqlDbType.NVarChar, 50);
           parm1.Value = this.TextBox1.Text.ToString();
           SqlParameter parm2 = new SqlParameter("@sid", SqlDbType.Int, 4);
           parm2.Value = this.dropdownlist1.SelectedValue.ToString();
           comm.Parameters.Add(parm1);
           comm.Parameters.Add(parm2);
           conn.Open();
           comm.ExecuteNonQuery();
           conn.Close();
           this.GridView1.DataSource = sdst2;
           this.GridView1.DataBind();
      

  3.   

    报下拉列表和gridveiw1没有定义。怎么回事。该如何定义啊。下拉列表和GRIDVERW是两个页面控件。
      

  4.   

    为什么 this.TextBox1.Text.ToString();
    就可以呢。