Home All Groups Group Topic Archive Search About

DropDownList -- setting by text?

Author
1 Aug 2006 6:48 PM
matt
hello,

what is the most-effcient manner to set the selected-item of an
existing dropdownlist, when you only have the text (not the value) of
the to-be-selected-item?

currently, this is what im doing:

    ddlIFoo.SelectedValue = ddlIFoo.Items.FindByText(theText).Value;



thanks!
matt

Author
2 Aug 2006 6:38 AM
Alessandro Zifiglio
Matt, have you had problems with the FindByText and FindByValue method ?
I'd say its time to move on if this is working for you. From what you are
trying to achieve, it seems to me that you want to Find-By-Text and are
indeed using the right method. If you are unhappy with this, then you can
manually loop through all items till you find a matching item whose
ListItem.Text matches the Text you want to match, while setting that
listItems.selected property to true. Not very elegant and unnecessary since
you would be reinventing the wheel =P

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

<m***@mailinator.com> ha scritto nel messaggio
Show quoteHide quote
news:1154458116.164030.74640@h48g2000cwc.googlegroups.com...
> hello,
>
> what is the most-effcient manner to set the selected-item of an
> existing dropdownlist, when you only have the text (not the value) of
> the to-be-selected-item?
>
> currently, this is what im doing:
>
>    ddlIFoo.SelectedValue = ddlIFoo.Items.FindByText(theText).Value;
>
>
>
> thanks!
> matt
>