F
F
fandorin_362016-10-03 21:50:31
ASP.NET
fandorin_36, 2016-10-03 21:50:31

Access all properties of the selected dropdownlist object?

There is a table which objects are placed in dropdownlist. It is necessary to extract all selectedItem properties on buttonClick and place their function. How to get access to all properties (of which there are more than two), while it turns out to use only the Text and Value properties? In webforms, I specified a collection of type List<> as DataSourse for combobox and got access to all properties of the selected element. Here is a piece of code in which I specify Name as the output property.

protected void Page_Load(object sender, EventArgs e)
{
    foreach (Weapon weapon in GetWeapons())
    {
        DropDownListOfWeapon.Items.Add(weapon.Name);
    }

}

protected IEnumerable<Weapon> GetWeapons()
{
    return weaponRepository.Weapons
        .OrderBy(a => a.Name);

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question