DropDownList1启用了autopostback,
DropDownList2取消了autopostback,
现在DropDownList2能根据DropDownList1的值来读取数据,
但是无论怎么选Response.Write(DropDownList2.SelectedItem.Text)  显示出来的值总是DropDownList2里面的第一项
大神们,到底是哪里出问题啦???

解决方案 »

  1.   

    public partial class member_mb_apply : System.Web.UI.Page
    {
        itemBLL ib = new itemBLL();
        memberBLL mb = new memberBLL();
        applyBLL ab = new applyBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            string mname = DropDownList1.SelectedValue.ToString();
            DropDownList2.DataSource = ib.getallitem(mname);
            DropDownList2.DataTextField = "item";
            DropDownList2.DataValueField = "item";
            DropDownList2.DataBind();
            string id = Session["id"].ToString();
            register r = mb.SelectRecordByid(id);
            TextBox1.Text = r.name;
            TextBox2.Text = r.id;
            TextBox3.Text = r.sex;
            TextBox4.Text = r.birthday.ToString();
        }
        protected void Button6_Click(object sender, EventArgs e)
        {
            apply a = new apply();
            a.mname = DropDownList1.SelectedItem.Text;
            a.item = DropDownList2.SelectedItem.Text;
            a.name = TextBox1.Text;
            a.id = TextBox2.Text;
            a.sex = TextBox3.Text;
            a.birthday =DateTime.Parse(TextBox4.Text);
            a.phone = TextBox5.Text;
            a.team = TextBox6.Text;
            ab.Insertapply(a);
            Response.Write("<script>alert('报名成功!');</script>");
        }
    }
      

  2.   

        protected void Page_Load(object sender, EventArgs e)
        {
          if(!IsPostBack)
          {
            string mname = DropDownList1.SelectedValue.ToString();
            DropDownList2.DataSource = ib.getallitem(mname);
            DropDownList2.DataTextField = "item";
            DropDownList2.DataValueField = "item";
            DropDownList2.DataBind();
            string id = Session["id"].ToString();
            register r = mb.SelectRecordByid(id);
            TextBox1.Text = r.name;
            TextBox2.Text = r.id;
            TextBox3.Text = r.sex;
            TextBox4.Text = r.birthday.ToString();
          }
        }
        
      

  3.   

    嗯,同样楼上的,不要每次都在pageload初始化加载控件数据,加ispostback判断
      

  4.   

    Refer:
    http://www.cnblogs.com/insus/archive/2013/05/10/3070348.html
    http://www.cnblogs.com/insus/archive/2012/10/16/2725307.html
    http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html