根据下拉列表中选择的月份和年份填充日期 [英] Populate date according to month and year selected in dropdown list

查看:99
本文介绍了根据下拉列表中选择的月份和年份填充日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个下拉列表,分别为年,月和日期。现在我想根据用户选择的年份和月份填充我的日期。我想尝试使用普通的下拉列表,所以我暂时排除了日期时间选择器的选项。



这是我的代码,我是正常使用以填充值:



  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());
}
}



我能做些什么才能使其正常工作?

解决方案

< BLOCKQUOTE>可以使用 DateTime.DaysInMonth方法 [ ^ ]获取通过的天数年和月。然后在循环中使用此结果填充日期下拉列表。


阅读本文..



Day下拉 [ ^ ]


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:

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?

解决方案

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.


Read this article..

Day DropDown[^]


这篇关于根据下拉列表中选择的月份和年份填充日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆