如何从3个下拉列表中选择数据并在文本框中显示结果

时间:2017-11-21 07:12:29

标签: c# sql asp.net aspxcombobox

我有3个下拉列表,我需要从这些下拉列表中选择数据并在文本框而不是网格上显示结果。在最后一个下拉列表的selectedIndexChange上,我想在文本框中填充数据。例如,在文本框上显示最小值和最大值。

这是我在选择

时需要selectedOndexChanged的最后一次下拉菜单
protected void ddlPaperLevel_SelectedIndexChanged(object sender, EventArgs 
e)
    {
        try
        {
            lblError.Text = "";
            string paperlevel = ddlPaperLevel.Text.Trim();

            DataTable specs = new DataTable();

            if ((specs = WIP.GetLabSpecs()).Rows.Count > 0)
            {
                for (int i = 0; i < specs.Rows.Count; i++)
                {
                    if (i == 0)        //Fluting 125 Special
                    {
                        txtFlut125gsmN.Text = specs.Rows[i]
   ["GramageMin"].ToString().Trim();
                        txtFlut125gsmX.Text = specs.Rows[i]
   ["GramageMax"].ToString().Trim();
                        txtFlut125MoistN.Text = specs.Rows[i]
   ["MoistMin"].ToString().Trim();
                        txtFlut125MoistX.Text = specs.Rows[i]
   ["MoistMax"].ToString().Trim();
  }

3 个答案:

答案 0 :(得分:1)

textbox1.text=
    DropDownList1.SelectedItem.Text+
    DropDownList2.SelectedItem.Text+
    DropDownList3.SelectedItem.Text+(and So on);

答案 1 :(得分:1)

您可以轻松地为您的结果编写代码

protected void dropdownlist3_SelectedIndexChanged(object sender, EventArgs e)
{
     string strddlText1 = Convert.ToString(dropdownlist1.SelectedItem.Text);
     string strddlText2 = Convert.ToString(dropdownlist2.SelectedItem.Text);
     string strddlText3 = Convert.ToString(dropdownlist3.SelectedItem.Text);
     if(strddlText1 != "" && strddlText2 != "" && strddlText3 != "")
     {
       Textbox1.Text = strddlText1 + " " + strddlText2  + " " + strddlText3;
     }
}

答案 2 :(得分:0)

将值保存在变量中,当选择最后一个下拉框时,取出所有值并将它们放在文本框中:

Texbox1.Text = "valuesFromDropdown"