2014年7月13日 星期日

[RESOLVED] DropDownList allow 1 to 40


how do i create a drop list from 1 to 40... without out writing 40 plus lines...


see example below which allows the user to select 1 to 10, but if this needs to be extended to 40 then there will be 40 plus lines!!!





































Try this:


for (int i = 0; i <= 40; i++)
{
dropDownList.Add(new ListItem(i,i); //the first i is for text, second for value
}




You could create a collection that would holds the numbers 1 to 40 and then bind them to your DropDownList. In this case you would need to use code-behind to populate your List.


沒有留言:

張貼留言