SPandya
SPandya

Reputation: 1209

Week Dates on week number click

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

Answers (2)

Bradley Gatewood
Bradley Gatewood

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

Jd30814
Jd30814

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

Related Questions