I would like to display a week of dates with the default being today's date on a drop down list. How can I do this?
I was also told to "use class DateTime.Now, and convert the data value into a string".
Any help is appreciated!
I would like to display a week of dates with the default being today's date on a drop down list. How can I do this?
I was also told to "use class DateTime.Now, and convert the data value into a string".
Any help is appreciated!
これを試して:
//Get Start And End
int delta = Convert.ToInt32(DateTime.Now.DayOfWeek);
delta = delta == 0 ? delta + 7 : delta;
DateTime moday = DateTime.Now.AddDays(1 - delta);
DateTime sunday = DateTime.Now.AddDays(7 - delta);
//Get Date Range
List<DateTime> allDates = new List<DateTime>();
//Add To Your List
for (DateTime i = moday; i <= sunday; i = i.AddDays(1))
{
DropDownList1.Items.Add(i.Date.DayOfWeek);
}
//Select Today Name
DropDownList1.SelectedItem = DateTime.Today.Date.DayOfWeek;
編集済み
この形式の場合(mm/dd/yyy)
//Add To Your List
for (DateTime i = moday; i <= sunday; i = i.AddDays(1))
{
comboBox1.Items.Add(i.Date.ToShortDateString());
}
//Select Today Date(dd/mm/yyy)
comboBox1.SelectedItem = DateTime.Today.ToShortDateString();