this code maybe can help you:
I modify the code in the response of this post:
Get a list of weeks for a year - with dates
You only need a DropDownList called DropDownList1 and paste the code in Page_Load event to test it.
var jan1 = new DateTime(DateTime.Today.Year, 1, 1);
var startOfFirstWeek = jan1.AddDays(1 - (int)(jan1.DayOfWeek));
var weeks =
Enumerable
.Range(0, 54)
.Select(i => new
{
weekStart = startOfFirstWeek.AddDays(i * 7)
})
.TakeWhile(x => x.weekStart.Year <= jan1.Year)
.Select(x => new
{
x.weekStart,
weekFinish = x.weekStart.AddDays(6)
})
.SkipWhile(x => x.weekFinish < jan1.AddDays(1))
.Select((x, i) => new
{
x.weekStart,
x.weekFinish,
weekNum = i + 1
});
//After get weeks' information, manipulate it to get the results.
DateTime Today = Convert.ToDateTime(DateTime.Now.Date.ToShortDateString()); //Convert to ShortDate to delete the HH:mm:ss
string lblItem = "";
foreach (var X in weeks)
{
//Check the Month and the Year must be from the actual Month
if (X.weekStart.Month == Today.Month || X.weekFinish.Month == Today.Month && X.weekFinish.Year == Today.Year)
{
lblItem = "#" + X.weekNum + " " + X.weekStart.ToShortDateString() + " - " + X.weekFinish.ToShortDateString();
DropDownList1.Items.Add(lblItem); //Add item in DropDownList
if (Today >= X.weekStart && Today <= X.weekFinish) //Check if the current date is between the week
DropDownList1.SelectedValue = lblItem; //Select the current week
}
}
if you want to add the items with values manually, you can do this. And then compare the items with the current date, as i do in the code.
Hope this help.