Click here to Skip to main content
15,911,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 dropdown list each for year, month and date. Now I want to populate my dates according to year and month selected by the user. I want to try it using normal dropdown list, so I'm ruling out the option of datetime picker for the time being.

This is my code which i'm using normally to fill the values:

C#
protected void Call_Date()
{
    for (int i = 1; i <= 31; i++)
    {
        date0.Items.Add(i.ToString());

    }

    for (int j = 1; j <= 12; j++)
    {
        month0.Items.Add(j.ToString());

    }

    for (int k = DateTime.Now.Year; k <= 2020; k++)
    {
        year0.Items.Add(k.ToString());
    }
}

What can I do to make it work accordingly?
Posted
Comments
[no name] 8-Feb-13 2:23am    
you want to display selected date,month,year from the dropdown selected
BlehBlahBah 8-Feb-13 2:27am    
I don't want to display it. I just want to populate it. For eg. when the user will select year 2011, then month February should have date till 28. Otherwise if he selected 2012, then date from 1 to 29 should be shown.

You can use DateTime.DaysInMonth Method[^] to get the number of days by passing the year and month. Then use this result in a loop to populate the days dropdown.
 
Share this answer
 
Read this article..

Day DropDown[^]
 
Share this answer
 

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