Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert item as LAST option in a dropdown list

Tags:

c#

asp.net

I know to add an item as the first item, I use:

ddlTest.Items.Insert(0, new ListItem("---New First Item---", "-1"));

I tried -1 as the index but then I didn't even see the item. How to I add an item as the last item in the list without knowing its index number (because the dropdown is populated from a database)?

like image 297
citsonga Avatar asked Dec 14 '22 22:12

citsonga


1 Answers

to add to the LAST position, just add to the list as

ddlTest.Items.Add(new ListItem("---New First Item---", "-1"));

as it will append to the last place by default.

like image 75
balexandre Avatar answered Jan 06 '23 16:01

balexandre