Selecting the nth item added to a dropdown box

S

sck10

Hello,

I am using the following and am trying to figure out how to select the nth
item of a list in a DropDownList.


//Insert and Add items to the DropDownList
ddlPayStatus.Items.Insert(0, new ListItem("Non Selected", "Non
Selected"));

This selects the value "Non Selected"
ddlPayStatus.Items.FindByValue("Non Selected").Selected = true;

Select the nth item
ddlPayStatus.Items.IndexOf(0).Selected = true;

Thanks, sck10
 
W

Walter Wang [MSFT]

Hi,

You can use the SelectedIndex property to change the selected item in
DropDownList:

dropDownList1.SelectedIndex = 0;

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top