Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

I want to display Days, Months and Year in 3 different Drop Downlist box.
If it is in ASP, I will increment the value from 1 to 30 in Days Field using VB Script and for loop.
But now I am working in ASP.Net, Kindly suggest is there provision to auto increment the days or I have to hardcode the values from 1 to 30.
Posted

Here is a similar thread.
for loop in dropdownlist box ?[^]
 
Share this answer
 
Hi,

In ASP.NET also you do the same.

try this in Page Load function

C#
//dropdownlist1 display days
if(!IsPostBack)
{
 dropdownlist1.Items.Clear();

 for(int i=1;i<=30;i++)
 {
    dropdownlist1.Items.Add(new ListItem(i,i));
 }

}


Hope it works.
 
Share this answer
 
v3
Comments
Ankur\m/ 11-Sep-12 6:19am    
To make it better, use DateTime.DaysInMonth method instead of hard coding the no. of days. :)
Karthik Harve 11-Sep-12 6:20am    
ofcourse.
Arunprasath Natarajan 11-Sep-12 7:17am    
Tan Q it means a lot
Karthik Harve 11-Sep-12 7:18am    
welcome. Happy coding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900