我做了个搜索,由DropDownList1,DropDownList2和button组成,先选择DropDownList1中的某项,然后自动刷新一下,使DropDownList2有数据,也就是DropDownList2的数据是动态的,随DropDownList1的项而改变,DropDownList1的AutoPostBack必须为ture,否则DropDownList2无数据.
现在的问题是点击button,不响应后面的事件,事件已经加载过了.
各位说说是什么问题,如何解决?

解决方案 »

  1.   

    有没有加
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    看看是不是写错了?
    在页面上重新放一个Button看能不能响应事件?
    你说的问题和DropDownList没有关系
      

  2.   

    把DropDownList1的AutoPostBack必须为false,就响应,加载了this.Button1.Click += new System.EventHandler(this.Button1_Click);点击button,跟踪不上啊,一点反应都没有...
      

  3.   

    你的Page_Load的里是如何写的,检查一下
      

  4.   

    还有你DropDownList1_SelectedIndexChanged里面也检查一下
      

  5.   

    namespace HLSoft.HFHouseBiz.Web.NewHou
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using HLSoft.HFHouseBiz.Business.NewHouse; /// <summary>
    /// Search 的摘要说明。
    /// </summary>
    public class HouSearch : System.Web.UI.UserControl
    {
    protected System.Web.UI.WebControls.DropDownList Dropdownlist3;
    protected System.Web.UI.WebControls.ImageButton ImageButton1;
    protected System.Web.UI.WebControls.DropDownList ddlDISTRICT;
    protected System.Web.UI.WebControls.DropDownList ddlItem;
    protected System.Web.UI.WebControls.DropDownList Dropdownlist2; private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.ddlDISTRICT.SelectedIndexChanged += new System.EventHandler(this.ddlDISTRICT_SelectedIndexChanged);
    this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void ddlDISTRICT_SelectedIndexChanged(object sender, System.EventArgs e)
    {

    this.ddlItem.Items.Clear();
    if(this.ddlDISTRICT.SelectedIndex != 0)
    {
    //绑定项目
    DataView dv = ItemDAL.GetAllItemInfo().Tables[0].DefaultView; this.CurrentDISTRICT = this.ddlDISTRICT.SelectedValue; this.CurrentPRICE = this.Dropdownlist3.SelectedValue; string ss = CurrentPRICE; string wss="DISTRICT = '"+CurrentDISTRICT +"'";
    dv.RowFilter = "DISTRICT = '"+CurrentDISTRICT +"'"; this.ddlItem.DataSource = dv;
    this.ddlItem.DataTextField = "ITEM";
    this.ddlItem.DataValueField = "ITEMID";
    this.ddlItem.DataBind();
    }

    this.ddlItem.Items.Insert(0,(new ListItem("-请选择项目-","0")));

    } private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
    this.CurrentDISTRICT = this.ddlDISTRICT.SelectedValue;

    this.CurrentPRICE = this.Dropdownlist3.SelectedValue;
    string temp1 = CurrentDISTRICT;
    string temp2 = CurrentLAYOUT;
    string temp3 = CurrentPRICE;
    string temp4 = CurrentITEMID; if(temp1 == "0" && temp2 == "0" && temp3 == "0" && temp4 == "0") 
    {
    Response.Redirect("index.aspx");
    }
    else if(temp1 != "0" && temp4 != "0" && temp2=="0" && temp3=="0")
    {
    Response.Redirect("NewHouseItems.aspx?ITEMID="+temp4); 
    }
    else if(temp1 != "0" && temp2 != "0" && temp3 != "0" && temp4 != "0")
    {
    Response.Redirect("SearchResult.aspx?CurrentDISTRICT="+temp1+"&CurrentLAYOUT="+temp2+"&CurrentPRICE="+temp3+"&CurrentITEMID="+temp4);
    }
    else if(temp1 != "0" && temp4 != "0" && temp2 != "0" && temp3=="0")
    {
    Response.Redirect("SearchResult.aspx?CurrentDISTRICT="+temp1+"&&CurrentLAYOUT="+temp2+"&CurrentITEMID="+temp4);
    }
    else if(temp1 != "0" && temp4 != "0" && temp3!= "0" && temp2=="0")
    {
    Response.Redirect("SearchResult1.aspx?CurrentDISTRICT="+temp1+"&&CurrentPRICE="+temp3+"&CurrentITEMID="+temp4);
    }
    else if((temp1 != "0"|| temp3 != "0" || temp4 != "0") && temp2 == "0")
    {
    Response.Redirect("SearchResult1.aspx?CurrentDISTRICT="+temp1+"&CurrentLAYOUT="+temp2+"&CurrentPRICE="+temp3);
    }
    else
    {
    Response.Redirect("SearchResult.aspx?CurrentDISTRICT="+temp1+"&CurrentLAYOUT="+temp2+"&CurrentPRICE="+temp3); 
    }
    }
    #region 页面属性 private string CurrentDISTRICT
    {
    get
    {
    return (string)ViewState["CurrentDISTRICT"];
    }
    set
    {
    ViewState["CurrentDISTRICT"] = value;
    }
    } private string CurrentLAYOUT
    {
    get
    {
    return (string)ViewState["CurrentLAYOUT"];
    }
    set
    {
    ViewState["CurrentLAYOUT"] = value;
    }
    } private string CurrentPRICE
    {
    get
    {
    return (string)ViewState["CurrentPRICE"];
    }
    set
    {
    ViewState["CurrentPRICE"] = value;
    }
    } private string CurrentITEMID
    {
    get
    {
    return (string)ViewState["CurrentITEMID"];
    }
    set
    {
    ViewState["CurrentITEMID"] = value;
    }
    }
    #endregion }
    }
      

  6.   

    问题可能出在this.ddlItem.Items.Insert(0,(new ListItem("-请选择项目-","0")));这句话。
    是该写在if句中还是else
      

  7.   

    dropdownlist的数据绑定写在page_load的if(!ispostback)事件里