By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

Calendar day binding

P: n/a
I am binding some data to a calendar control. Since I don't want to return
all the Data from the DB, I would like to return only the data for the
current view of the calendar. The calendar has always 42 cells.
I would like to know if there is a way to know which date is displayed in
the first cell of the calendar. Unfortuantely, there is no index in the
calendar. ( I could go with the SelectedDate.Today as a reference and then
subtract and add 42 days but i would prefer if there is onther solution to
get the exact dates disoplayed..
Thx
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"patrick delifer" <pd******@videotron.ca> wrote in message news:%K*********************@wagner.videotron.net. ..
current view of the calendar. The calendar has always 42 cells.
I would like to know if there is a way to know which date is displayed in
the first cell of the calendar.


I'm not certain which Calendar you're using, so this may not be applicable.

On the ASP.NET Calendar (System.Web.UI.WebControls) you can get
the "current month" off of the TodaysDate property. The first row should
contain the first day of that current month ( Month 1, Year ).

Then, the date of the first day of the first week depends on what Day
of the Week that is, i.e., February 1, 2005 was a Tuesday.

Therefore, in a culture where Sunday is the first Day of the Week (which
you can read off of the FirstDayOfWeek property of the afforementioned
ASP.NET Calendar; in particular it will be Monday in some cultures)
then you subtract one day (Monday = 0, Tuesday = 1, ...) from the
number of days in the month preceding the "current month" (31 days
hath January...).

Answer: Sunday, January 30, 2005.

In summary -- find out what Month you're in, go to the first Day in that
Month, calculate the Day Of the Week, and then subtract to reach the
Date of the First Day Of Week (the amount you subtract is determined
by what Day Of the Week the first Day in the Month is, and the number
you subtract from is determined by the number of Days in the preceding
Month).

If you Calendar control doesn't keep the first day of the month on the
first row (if it just scrolls through six weeks at a time) then this algorithm
won't work all the time because sometimes you'll encounter the whole
first week as being days from the previous Month.
Derek Harmon
Nov 16 '05 #2

P: n/a
Good enough. But this takes into account the TodaysDate. I would have to
keep track of the todays date for other events (When the user selects a
previous or next month). Luckily, the VisibleMonthChanged of the calendar
control has a NewDate property which gets the date of first day of the
month.

I'll experiment with your suggestion. Thanks
"Derek Harmon" <lo*******@msn.com> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
"patrick delifer" <pd******@videotron.ca> wrote in message news:%K*********************@wagner.videotron.net. ..
current view of the calendar. The calendar has always 42 cells.
I would like to know if there is a way to know which date is displayed in the first cell of the calendar.


I'm not certain which Calendar you're using, so this may not be

applicable.
On the ASP.NET Calendar (System.Web.UI.WebControls) you can get
the "current month" off of the TodaysDate property. The first row should
contain the first day of that current month ( Month 1, Year ).

Then, the date of the first day of the first week depends on what Day
of the Week that is, i.e., February 1, 2005 was a Tuesday.

Therefore, in a culture where Sunday is the first Day of the Week (which
you can read off of the FirstDayOfWeek property of the afforementioned
ASP.NET Calendar; in particular it will be Monday in some cultures)
then you subtract one day (Monday = 0, Tuesday = 1, ...) from the
number of days in the month preceding the "current month" (31 days
hath January...).

Answer: Sunday, January 30, 2005.

In summary -- find out what Month you're in, go to the first Day in that
Month, calculate the Day Of the Week, and then subtract to reach the
Date of the First Day Of Week (the amount you subtract is determined
by what Day Of the Week the first Day in the Month is, and the number
you subtract from is determined by the number of Days in the preceding
Month).

If you Calendar control doesn't keep the first day of the month on the
first row (if it just scrolls through six weeks at a time) then this algorithm won't work all the time because sometimes you'll encounter the whole
first week as being days from the previous Month.
Derek Harmon

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.