为什么选择dropdownlist选项不会导致第二次回发?

时间:2010-01-27 12:47:30

标签: asp.net drop-down-menu postback

我有两个下拉列表,选择第一个下拉列表会导致回发,第二个下拉列表会被绑定...

  • 为什么第一个下拉列表的选定值再次被选中不会导致回发?

修改

 <asp:DropDownList ID="DLMatName" runat="server" OnSelectedIndexChanged="DlMeasurement_SelectedIndexChanged" AutoPostBack="true">
                                               </asp:DropDownList>


protected void DlMeasurement_SelectedIndexChanged(object sender, EventArgs e)
{

    if (DLMatName.SelectedIndex != 0)
    {
        DataTable dt = _materialInController.GetMeasurementsforMaterials(Convert.ToInt64(DLMatName.SelectedValue.ToString())).Tables[0];
        if (dt.Rows.Count > 1)
        {
            MeasurementTr.Visible = true;
            this.DlMeasurement.DataSource = dt;
            this.DlMeasurement.DataValueField = dt.Columns[0].ToString();
            this.DlMeasurement.DataTextField = dt.Columns[1].ToString();
            this.DlMeasurement.DataBind();
            this.DlMeasurement.Items.Insert(0, ListItem.FromString("Select"));
            this.LblMeasuremet.Visible = false;
            ErrorMsg.InnerHtml = "";             
        }
        else if (dt.Rows.Count == 1)
        {
            this.LblMeasuremet.Visible = true;
            this.LblMeasuremet.Text = dt.Rows[0].ItemArray[1].ToString();
            MeasurementTr.Visible = false;
            ErrorMsg.InnerHtml = "";       

        }
        else
        {

        }
    }
    else
    {
        MeasurementTr.Visible = false;
        this.LblMeasuremet.Visible = false;
        ErrorMsg.InnerHtml = "Select the materialType";
    }
    ScriptManager.RegisterClientScriptBlock(DLMatName, typeof(DropDownList), "Hideimage", "HideImageButtonDivforAdd();", true);

}

第一次选择的值回发时,第二次选择的值不回发...

1 个答案:

答案 0 :(得分:0)

您是否在页面的每个回发中重新绑定第二个下拉列表,即在您的Page_Load事件中,您是否有任何代码,例如:

protected void Page_Load(object sender, EventArgs e)
{
      if (DropDown1.SelectedIndex > 0)
      {
          // Rebind the second dropdown. 
      }
}

如果是这样,那么你错过了检查页面是否回复自己(Page.IsPostBack),这会导致你的问题。