w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
how to display all the mondays when you select monday in a calendar using Calendar control asp.net c#

I think the following code should help you in displaying all the Mondays of a particular month.

protected void Button1_Click1(object sender, EventArgs e) {

    DateTime dtime1 = new DateTime();
    dtime1 = Calendar1.SelectedDate;
    // get a list of all dates
    var dates = Enumerable.Range(1, DateTime.DaysInMonth(dtime1.Year,
dtime1.Month)).Select(n => new DateTime(dtime1.Year, dtime1.Month, n));
    // then filter mondays like following
    var mondays = from d in dates
                   where d.DayOfWeek == DayOfWeek.Monday
                   select d;
    List<DateTime> listOfMondays = mondays.ToList();
    // then you can loop through the listOfMondays and write it on the


© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.