I have now a dropdownlist of weeks
[code]
public static IEnumerable
{
var janFirst = new DateTime(DateTime.Today.Year + 1, 1, 1);
//beware different cultures, see other answers
var firstWeek = janFirst.AddDays(1 - (int)(janFirst.DayOfWeek));
return
Enumerable
.Range(0, 52)
.Select(i => new
{
weekStart = firstWeek.AddDays(i * 7)
})
.TakeWhile(x => x.weekStart.Year <= janFirst.Year)
.Select(x => new
{
x.weekStart,
weekFinish = x.weekStart.AddDays(6)
})
.SkipWhile(x => x.weekFinish < janFirst.AddDays(1))
.Select((x, i) => new SelectListItem
{
Text = new {weekNum = i + 1}.ToString(),
Value=(i+1).ToString(CultureInfo.InvariantCulture)
}
);
}//end method
[/code]
working in the view:
[code]
@Html.LabelFor(model => model.WeekNumber, "Week")
@Html.DropDownListFor(model => model.WeekNumber,Html.GetWeekNumbers(DateTime.Now))
@Html.ValidationMessageFor(model => model.Week.WeekNumber)
[/code]
And I have the current week, like this: Monday(17-05-2012), Tuesday(15-05-2012).
But how to get de dates of the week associated with the selecting week of the dropdownlist.
The dates of the week has to be saved in the database.
It is easier to sent the hole project.
So here is the hole project.
THX!!

EhteshamRank #3,979 · 374 reputationPosted May 18, 2012, 2:21 AM EDT
DateTime StartDate = DateTime.ParseExact("29-05-2012", "dd-MM-yyyy", null);
DateTime EndDate = StartDate;
//add 7 days to get ending date
EndDate += TimeWeek;
int Month = StartDate.Month;
while (StartDate != EndDate && StartDate.Month == Month)
{
MessageBox.Show(StartDate.ToString("dd MMM yyyy"));
StartDate += new TimeSpan(1, 0, 0, 0, 0);
}
albert albertRank #2,683 · 519 reputationPosted May 19, 2012, 12:51 AM EDT
thx for the replay. But I still dont understand how to get it in the view:
for example for monday:
[code]
@Html.LabelFor(model => model.Monday, "Maandag")
@Html.TextBoxFor(model => model.Monday, Html.GetWeekNumbers(DateTime.Now))
@Html.ValidationMessageFor(model => model.Monday)
[/code]
Maandag = monday. So if u select for example: week 1(2-01-2012) then u will get in de textbox of Maandag(monday): 2-01-2012.
Because I see in ur example DateTime StartDate = DateTime.ParseExact("29-05-2012", "dd-MM-yyyy", null); so that is hard coded?
But it has to be dynamic.
albert albertRank #2,683 · 519 reputationPosted May 19, 2012, 11:35 PM EDT
albert albertRank #2,683 · 519 reputationPosted May 20, 2012, 2:39 AM EDT
@Html.TextBoxFor(model => model.Monday ,new[]{new SelectListItem(){Text = DateTimeExtensions.GetWeekNumbers(DateTime.Now.ToString()) }})
EhteshamRank #3,979 · 374 reputationPosted May 21, 2012, 12:30 AM EDT
albert albertRank #2,683 · 519 reputationPosted May 21, 2012, 12:41 AM EDT
U see that I already have the dates for every week.
U only have to filter the specific dates in the textbox.
EhteshamRank #3,979 · 374 reputationPosted May 21, 2012, 1:15 AM EDT
But how to get de dates of the week associated with the selecting week of the dropdownlist.
My code snippet was tested and it does the above required task as you had mentioned...
You can just get date from string Monday(17-05-2012) as 17-05-2012 dynamically and use my code
If you cant understand please ignore my code
albert albertRank #2,683 · 519 reputationPosted May 21, 2012, 2:12 AM EDT
What is this then?
DateTime StartDate = DateTime.ParseExact("29-05-2012", "dd-MM-yyyy", null);
it is hardcoded and I dont see any dropdownlist in ur code.
if u understand it then u will fill it in the view, like this:
[code]
@Html.LabelFor(model => model.Monday, "Maandag")
@Html.TextBoxFor(model => model.Monday, htmlAttributes: new[]{ new SelectListItem(){Text = Html.GetWeekNumbers() }} )
@Html.ValidationMessageFor(model => model.Monday)
[/code]
Then u understand the meaning of it.
EhteshamRank #3,979 · 374 reputationPosted May 21, 2012, 6:09 AM EDT
You say i had to use dropdown list??What you expect we do your job by doing exact code?? only help is provided brother rest its up to you
i already said if you cant understand ignore my code and yes i understand what is listview control in winforms, WPF as well as in ASP.Net
Have a nice day best of luck
albert albertRank #2,683 · 519 reputationPosted May 21, 2012, 6:29 AM EDT
it has to do something with this method:
[code]
public static MvcHtmlString StateDropDown(this HtmlHelper helper,string name, DateTime date)
{
return MvcHtmlString.Create(value: Enumerable.Select(GetWeekNumbers(helper), x => x.Value).ToString());
//return MvcHtmlString.Create((GetWeekNumbers(helper).First().Text));
}//end method
[/code]
but I get strange output:
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Web.Mvc.SelectListItem,System.String]