473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Unselectable dates in Calendar

na
I need to make certain date selectable in a calendar control depending
on records found in a database. For example, if the 10/20/2006 and
11/20/2006 records exist in the database, then only enable and
highlight thoese two days in the calendar control. Also, I need to
disable all weekends. Is this doable? How do I do this in the
calendar control's DataBinding, Load, or PreRender event. Thanks.

Oct 13 '06 #1
5 4698
you do that in DayRender event of the Calendar Control

http://odetocode.com/Articles/223.aspx

--

Bruno Alexandre
København, Danmark

"a Portuguese in Denmark"

Blog. http://balexandre.blogspot.com/
Photos. http://www.flickr.com/photos/balexandre/
"na" <an********@yahoo.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I need to make certain date selectable in a calendar control depending
on records found in a database. For example, if the 10/20/2006 and
11/20/2006 records exist in the database, then only enable and
highlight thoese two days in the calendar control. Also, I need to
disable all weekends. Is this doable? How do I do this in the
calendar control's DataBinding, Load, or PreRender event. Thanks.

Oct 14 '06 #2
na
Thank you for your response.

Great article, but I need the dates rendered as text inside e.cell, not
as <Atag for those dates that have not data in the database. I used
e.cell.enabled=false, but it still render each date as <Ainside <TD>
tag. Thanks.

On Oct 14, 5:15 am, "Bruno Alexandre" <bruno.in...@gmail.comwrote:
you do that in DayRender event of the Calendar Control

http://odetocode.com/Articles/223.aspx

--

Bruno Alexandre
København, Danmark

"a Portuguese in Denmark"

Blog.http://balexandre.blogspot.com/
Photos.http://www.flickr.com/photos/balexandre/

"na" <android...@yahoo.comwrote in messagenews:11**********************@b28g2000cwb.g ooglegroups.com...
I need to make certain date selectable in a calendar control depending
on records found in a database. For example, if the 10/20/2006 and
11/20/2006 records exist in the database, then only enable and
highlight thoese two days in the calendar control. Also, I need to
disable all weekends. Is this doable? How do I do this in the
calendar control's DataBinding, Load, or PreRender event. Thanks.- Hidequoted text -- Show quoted text -
Oct 14 '06 #3
"na" <an********@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...

Great article, but I need the dates rendered as text inside e.cell, not
as <Atag for those dates that have not data in the database. I used
e.cell.enabled=false, but it still render each date as <Ainside <TD>
tag. Thanks.

Preventing days being "clickable" is extremely simple. All you do is clear
the controls in the <tdand then write the date back in so that it's still
visible.

E.g. the following code will prevent dates being clicked if they fall on a
weekend:

protected void cal_DayRender(object source, DayRenderEventArgs e)
{
if (e.Day.IsWeekend)
{
e.Cell.Controls.Clear();
e.Cell.Text = e.Day.DayNumberText;
}
}

You could also give the user some sort of visual hint that the weekend dates
are "different", maybe by changing the back colour of the <tdor the font
colour.

You can even get rid of the dates entirely. I sometimes do this if they fall
outside the current month e.g.

if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
e.Cell.Text = "&nbsp;"
}
Oct 14 '06 #4
na
Thanks, Mark. Now add one more twist. How do I disable the dates that
does not have record in a database? I hope I dont' have to connect to
the database and query it using the e.date as a parameter. It would be
too many connections and queries going on. Thanks.

On Oct 14, 3:19 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:
>
Preventing days being "clickable" is extremely simple. All you do is clear
the controls in the <tdand then write the date back in so that it's still
visible.

E.g. the following code will prevent dates being clicked if they fall on a
weekend:

protected void cal_DayRender(object source, DayRenderEventArgs e)
{
if (e.Day.IsWeekend)
{
e.Cell.Controls.Clear();
e.Cell.Text = e.Day.DayNumberText;
}

}You could also give the user some sort of visual hint that the weekend dates
are "different", maybe by changing the back colour of the <tdor the font
colour.

You can even get rid of the dates entirely. I sometimes do this if they fall
outside the current month e.g.

if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
e.Cell.Text = "&nbsp;"
}
Oct 15 '06 #5
"na" <an********@yahoo.comwrote in message
news:11********************@k70g2000cwa.googlegrou ps.com...
Thanks, Mark. Now add one more twist. How do I disable the dates that
does not have record in a database? I hope I dont' have to connect to
the database and query it using the e.date as a parameter. It would be
too many connections and queries going on
No of course not - that would be ridiculous.

I do this by querying the database once to return all records between the
start and end date of the calendar (or calendars) on the page, which I then
store in a List<DateTimegeneric collection. Then, on the DayRender, I
simply check if the generic list contains the key e.Date.

pseudo-code:

List<DateTimemlstDates = new List<DateTime>;

Page_Init or Page_Load
{
<clear out mlstDates>;
SqlDataReader objDR = <SqlDataReader of dates>;
while (objDR.Read())
{
mlistDates.Add(<Date from SqlDataReader>);
}
}

Calendar_DayRender
{
if (!mlstDates.ContainsKey(e.Date))
{
// disable the date in the Calendar;
}
}
Oct 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution....
2
by: Christopher M. Pieper | last post by:
I want to generate a resultset that is just a series of numbers in ascending order or perhaps a series of dates.. What I mean is, is there a way to generate a temporary table of dates given an...
4
by: Dale | last post by:
Hi Everyone, I've got a form that provides a pop-up calendar for users to select dates for requesting jobs to be completed. The calendar works great, but it unfortunately allows users to select...
0
by: ActiveUp | last post by:
http://www.activeup.com/products/components/activecalendar Active Calendar is an ASP.NET server control that allows users to select a date and/or time quickly using a professional looking date...
24
by: PromisedOyster | last post by:
Is there a way that I can get a resultset that contains unique dates in a given date range without the need to have a temporary table and a cursor? perhaps something like: declare @start_date...
2
by: Rachel Suddeth | last post by:
Is there a way to have the non-selectable dates (those before MinDate and after MaxDate) draw differently so my users can see right away what dates aren't allowed? I'm not seeing it... ...
9
by: Greg | last post by:
Hi, I have a table with "dates", i'd like to display those dates on a calendar. I've put a calendar in a form, linked to my "date" field, and it works, but only showing one "date" per calendar....
2
by: MobiusDick | last post by:
Hi All, I'm in the process of creating a database that allows users to enter details into a form which includes a date range as start and end dates. I have used the inbuilt Calendar Control...
2
by: gubbachchi | last post by:
Hi all, How will I change the color of the dates in the javascript calendar which already has some event entered for it. Like I have a form where the user enters the id and selects the date from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.