Selecting the nth item added to a dropdown box

  • Thread starter Thread starter sck10
  • Start date Start date
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
 
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.
 
Back
Top