adding values into a drop down list

C

Claudia Fong

Hi,

Is there a way to add dynamic values into a drop down list?

I mean, I will do a query to count how many items I have and then add
that number into the ddl.

For example if the query result is 9, then I will add item 1 to 9 into
drop down list. If is 8, I will add 1 to 8.. and so on.. the max is 10..


I usded to use this line to add, but I have to specify the value.. can I
put a variable instead?
drpCart.Items.Insert(0, new ListItem("1", "1"));


Cheers!

Claudi
 
A

Aidy

int count = 5;

for (int i = 1; i <= count; i++)

{

drpCart.Items.Add(new ListItem(i.ToString(), i.ToString()));

}
 

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,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top