Reputation: 1209
Is there any way in asp.net or using javascript that when someone clicks on the week number shown on the calendar and I can get the dates (Monday to Friday) on a label?
Upvotes: 5
Views: 653
Reputation: 248
Here is a server side solution in asp.net
Markup
<asp:Label ID="Label1" runat="server" Text="" />
<asp:Calendar runat="server" ID="Calendar1" OnSelectionChanged="Calendar1_SelectionChanged" />
Code Behind
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DateTime input = Calendar1.SelectedDate;
int delta = DayOfWeek.Sunday - input.DayOfWeek;
DateTime firstDay = input.AddDays(delta);
for (int i = 0; i < 7; i++)
Label1.Text += ((DateTime)(firstDay.Add(new TimeSpan(i, 0, 0, 0)))).ToShortDateString() + " -- ";
}
Upvotes: 4
Reputation: 155
Try this jsFiddle example.
$(".calendar").datepicker({
showWeek: true,
onSelect: function(dateText, inst) {
dateFormat: "'Week Number '" + $.datepicker.iso8601Week(new Date(dateText)),
$(this).val('Week:' + $.datepicker.iso8601Week(new Date(dateText)));
}
});
Upvotes: 4