Combo or Dropdownlist display a Text according to its value

-1

I do a search on my DB and bring, say, the number 237. This is the value of my Combo that is equivalent to the text Bradesco S / A. So I would like the Dopdownlist to display this text Bradesco S / A when I pass the value (237). I can not make it work. Here's what I've done.

for (int i = 0; i < cmbBancos.Items.Count - 1; i++)
                    {
                        if (cmbBancos.Items[i].Value == nm_banco)
                        {
                            cmbBancos_SelectedIndexChanged(this, EventArgs.Empty);
                            //cmbBancos.Text = cmbBancos.Items[i].Text.ToString();
                            break;
                        }
                    }

As above, it does not work and neither does the commented code, either. Does anyone know how to make this work?

Use WebForm and C #.

    
asked by anonymous 30.12.2014 / 13:00

1 answer

2

I believe it will serve you:

cmbBancos.SelectedValue = "237";

But this will only work if you have loaded the DropDownList by passing the Text and Value, for example:

cmbBancos.Items.Add(New ListItem("Bradesco S/A", "237"))
    
30.12.2014 / 13:13