1

I have 3 drop down lists, and I need to select data from these dropdown lists and display results on text boxes instead of a Grid. On selectedIndexChange of the last drop down I would like to populate the data on text boxes. e.g display minimum and maximum on text boxes.

This is the last drop down i need selectedOndexChanged when selecting

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();
  }
Youza
  • 23
  • 5
  • 1
    What do you mean "instead of a grid"? Can you show us your existing code? – IrishChieftain Nov 21 '17 at 07:14
  • sorry I will post my code. I mean I do not want to display in a table but in text boxes. – Youza Nov 21 '17 at 07:17
  • What are you expecting of us to do? Write all the code for you? You need to make your question more direct and show us what code you have (tried). But here is how i would do it: Just save the first two values of the dropdown boxes in a variable and when the last dropdown box is selected, check if the first two values aren't empty and then write the values to the text boxes. – Svenmarim Nov 21 '17 at 07:18
  • @Svenmarim I have edited and put my code thanks – Youza Nov 21 '17 at 07:21
  • @IrishChieftain I have edited and put my code – Youza Nov 21 '17 at 07:22

3 Answers3

1
textbox1.text=
    DropDownList1.SelectedItem.Text+
    DropDownList2.SelectedItem.Text+
    DropDownList3.SelectedItem.Text+(and So on);
daniele3004
  • 13,072
  • 12
  • 67
  • 75
vijayvicks
  • 161
  • 10
  • Thankyou so much... I am actually fetching data from the database based on the 3 selections from the 3 drop down lists. its displaying and clearing to the textboxes that am struggling with. my dropdown items are ok they are showing perfectly but its on selection of the dropdown that am struggling on – Youza Nov 21 '17 at 07:35
1

you can easly write code for you result

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;
     }
}
M.Y.Mnu
  • 718
  • 8
  • 22
  • Thanks let me try this out – Youza Nov 21 '17 at 07:30
  • are you passing that 3 dropdown list value in any method to fetch data from database ? – M.Y.Mnu Nov 21 '17 at 07:41
  • Yes @Y.M.Mnu... exactly how you say it. Thanks. So what I'm doing is select the 3 drop down lists, i already created tables where i fetch them. and based on the combination of the choices from 3 dropdowns I would like to display info to text boxes (Min, Max etc..) but display on the last drop down selection... i tried my code is not working maybe i'm doing something wrong – Youza Nov 21 '17 at 07:51
  • match your data type where you are passing them, debug you code. – M.Y.Mnu Nov 21 '17 at 08:48
  • **paperlevel** where are you using this variable i can't understand ? – M.Y.Mnu Nov 21 '17 at 08:52
0

Save the values in a variable and when the last dropdown box is selected, take all the values and put them in the textbox with:

Texbox1.Text = "valuesFromDropdown"
Svenmarim
  • 3,633
  • 5
  • 24
  • 56