1
votes

i have four dropdown lists, upon selecting each dropdown list in asp.net page textbox field should fill the value, which user selected in dropdownlist page, there is no SQL business here, for ex, ddl1 contains...Tiger Lion Deer ddl2 contains...Siberia RSA Namibia ddl3 contains...Carnivore Carnivore Herbivore

if users select tiger from ddl1, siberia from ddl2 and cornivore from ddl3, textbox field should update as, Tiger Siberia Carnivore i have used StringBuilder with append class below like this,

        public List<StringBuilder> GetAnimalDetails()
    {
        StringBuilder typo = new StringBuilder();
        typo.Append(DropDownListBranch.SelectedValue);
        typo.Append(" ");
        typo.Append(DropDownListMilestone.SelectedValue);
        typo.Append(" ");
        typo.Append(DropDownListType.SelectedValue);
        typo.Append(" - ");
        typo.Append(DropDownListVersion.SelectedValue);
        return typo.ToString().ToList();

    }
1
So, whats your problem here?Vanest
So what is the issue here ? Also, I would suggest using SelectedText instead of SelectedValue incase you are not getting proper text. @Vanest - Lol. Timing.Matt Murdock
@Harvey : I think SelectedText OR SelectedValue is fine with me. You can bind the same field in SelectedText AND SelectedValue right?Heinz Siahaan
SelectedText will give you the text that you can see in the dropdown whereas SelectedValue will give you the value associated with each of those items. So are you getting any errors/exceptions ?Matt Murdock

1 Answers

0
votes

Considering the simple textbox filling with dropdown values, you could try something like,

    public string GetAnimalDetails()
    {
        string typo = string.Empty;

        typo = DropDownListBranch.SelectedValue;
        if (!string.IsNullOrEmpty(typo) && !string.IsNullOrEmpty(DropDownListMilestone.SelectedValue))
        {
            typo += " ";
        }
        typo = typo + DropDownListMilestone.SelectedValue;
        if (!string.IsNullOrEmpty(typo) && !string.IsNullOrEmpty(DropDownListType.SelectedValue))
        {
            typo += " ";
        }
        typo = typo + DropDownListType.SelectedValue;
        if (!string.IsNullOrEmpty(typo) && !string.IsNullOrEmpty(DropDownListVersion.SelectedValue))
        {
            typo += " - ";
        }
        typo += DropDownListVersion.SelectedValue;

        return typo;
    }


    protected void DropDownListBranch_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtAnimalDetails.Text = GetAnimalDetails();
    }

    protected void DropDownListMilestone_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtAnimalDetails.Text = GetAnimalDetails();
    }

    protected void DropDownListType_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtAnimalDetails.Text = GetAnimalDetails();
    }

    protected void DropDownListVersion_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtAnimalDetails.Text = GetAnimalDetails();
    }

Hope this helps...