基于下拉列表选择值的文本消息

时间:2019-03-15 03:54:41

标签: c# sql asp.net cascadingdropdown

我的下拉列表具有以下值:用户选择A1,文本框将显示+1,选择A2,消息显示+2,如果B1,消息显示-1和B2消息显示-2。我选择A1,+ 1出现,A2,+ 2出现。但是,当我选择B1时,出现+1,而B2,+ 2。为什么As答案仅不出现Bs?需要帮助。

我的aspx.cs

protected void ddlJM1_SelectedIndexChanged(object sender, EventArgs e)
{
    int IntentID = Convert.ToInt32(ddlJM1.SelectedValue.ToString());
    FillYes(IntentID);

    if (ddlJM1.SelectedIndex == 1)
    {
        ddlJM2.Enabled = true;
        ddlJM3.Enabled = false;
        ddlJM2.SelectedIndex = 0;
        lblMsgJM.Text = "";
    }

    if (ddlJM1.SelectedIndex == 2)
    {
        ddlJM2.Enabled = true;
        ddlJM2.SelectedIndex = 0;

        ddlJM3.Enabled = false;
        lblMsgJM.Text = "";
    }

}

protected void ddlJM2_SelectedIndexChanged(object sender, EventArgs e)
{
    int YesID = Convert.ToInt32(ddlJM2.SelectedValue.ToString());
    FillJob(YesID);

    if (ddlJM2.SelectedIndex == 1)
    {
        ddlJM3.Enabled = true;
        lblMsgJM.Text = "";
    }

    if (ddlJM2.SelectedIndex == 2)
    {
        ddlJM3.Enabled = false;

    }

    if (ddlJM2.SelectedIndex == 3)
    {
        ddlJM3.Enabled = true;
        lblMsgJM.Text = "";
    }

    if (ddlJM2.SelectedIndex == 4)
    {
        ddlJM3.Enabled = false;
        lblMsgJM.Text = "Please consult / review with ODD focal person";
    }

}


 protected void ddlJM3_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddlJM3.SelectedIndex == 1)
    {
        lblMsgJM.Text = "+1";
    }
    if (ddlJM3.SelectedIndex == 2)
    {
        lblMsgJM.Text = "+2";
    }

     if (ddlJM3.SelectedIndex == 3)
    {
        lblMsgJM.Text = "-1";
    }
    if (ddlJM3.SelectedIndex == 4)
    {
        lblMsgJM.Text = "-2";
    }
}

 private void FillJob(int YesID) //for ddlJM3
    {
        string strConn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
        SqlConnection con = new SqlConnection(strConn);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "SELECT AlphabetID, Alphabet FROM TableJob WHERE YesID =@YesID";
        cmd.Parameters.AddWithValue("@YesID", YesID);
        DataSet objDs = new DataSet();
        SqlDataAdapter dAdapter = new SqlDataAdapter();
        dAdapter.SelectCommand = cmd;
        con.Open();
        dAdapter.Fill(objDs);
        con.Close();

        if (objDs.Tables[0].Rows.Count > 0)
        {
            ddlJM3.DataSource = objDs.Tables[0];
            ddlJM3.DataTextField = "Alpahabet";
            ddlJM3.DataValueField = "AlphabetID";
            ddlJM3.DataBind();
            ddlJM3.Items.Insert(0, "--Select--");

        }

     }

1 个答案:

答案 0 :(得分:0)

请比较这样选择的值

protected void ddlJM3_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddlJM3.SelectedItem.Text.ToLower() == "a1")
    {
        lblMsgJM.Text = "+1";
    }
    if (ddlJM3.SelectedItem.Text.ToLower() == "a2")
    {
        lblMsgJM.Text = "+2";
    }

    if (ddlJM3.SelectedItem.Text.ToLower() == "b1")
    {
        lblMsgJM.Text = "-1";
    }
    if (ddlJM3.SelectedItem.Text.ToLower() == "b2")
    {
        lblMsgJM.Text = "-2";
    }
}