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!!
albert albertPosted May 21, 2012, 10:29 AM
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]
EhteshamPosted May 21, 2012, 10:09 AM
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 albertPosted May 21, 2012, 6:12 AM
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.
EhteshamPosted May 21, 2012, 5:15 AM
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 albertPosted May 21, 2012, 4:41 AM
U see that I already have the dates for every week.
U only have to filter the specific dates in the textbox.
EhteshamPosted May 21, 2012, 4:30 AM
albert albertPosted May 20, 2012, 6:39 AM
@Html.TextBoxFor(model => model.Monday ,new[]{new SelectListItem(){Text = DateTimeExtensions.GetWeekNumbers(DateTime.Now.ToString()) }})
albert albertPosted May 20, 2012, 3:35 AM
albert albertPosted May 19, 2012, 4:51 AM
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.
EhteshamPosted May 18, 2012, 6:21 AM
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);
}