easily change month and year in calendar in asp.net - c#

I want to use calendar to select a date, but it takes time when I have to pick another month or year, because I can only pick another month by clicking prev or next month one by one, is there any other way to make it easier to select a month or a year? maybe something like dropdownist

Most people use a javascript library for a responsive calendar control allowing you to quickly select a month/year.
Two possibilities include:
Microsoft's Ajax Control Toolkit. Note that in the sample you can click the Month/Year header to quickly select a different month or year.
or
jQuery Datepicker with Month/Year dropdowns.

If you're looking at a dropdownlist, you have to build it yourself. Do take note of the Leap Year algorithm.

Related

How to select the "selected Date" in asp:Calendar?

The question sounds illogical, but it is not:
I have 2 dates "Target" and "Actual". Usually the "Actual" date is very close to "Target", but not necessarily to the current date. To avoid the multiple clicks in the calendar that would navigate you to the month/year of interest, I set the selected date to my "Target" date when it is opened. This works great, BUT does not allow me to select that day, with the calendar closing automatically after selecting.
Any idea to solve this or any known alternative?
If you have a Calendar1 component, you can use a code like:
DateTime tomorrow = DateTime.Today.AddDays(1);
Calendar1.TodaysDate = tomorrow;
Calendar1.SelectedDate = Calendar1.TodaysDate;
When this calendar changed SelectionChanged the selected date, you can set the other calendar.
Tell me if you need more detail.

Bind drop down list to calendar with conditions

I'm new to ASP.NET and C# and I'm having trouble completing a project. I'm trying to create a page where a user can select an item from a drop-down list, which contains four options. Each option is tied to specific days and times of the week. I'm trying to make it so when a user selects an option where the specified days are Monday, Wednesday, and Friday, it makes it so the corresponding calendar only allows for Monday, Wednesday, or Friday to be selected.
No way ofdoing this the way you want to. Check out some javascript calendar pickers that can be configured to only allow certain months and use that on front end.
Perhaps you can store the current selection and then in the on select event if the event is one you don't want the user to select then reselect the stored (previous) selection?

C# Datetimepicker : Set forecolor to Specific Date

I am using a datetimepicker in my application. I want it to display specific dates (in this case, all Holidays of a month) with one specific color (i.e. The holidays will be shown as red or blue or any color) when the datetimepicker is clicked and its monthview (i don't know exact name of this) is prompted. Is it possible with default datetimepicker ?
Suppose there are holidays in August are all the public holidays (in this case, every fri and sat) and some specific holidays (such as 13 Aug,19 Aug etc) and I want to show them in red/blue color. This will also occur when I change the month to September (or any month).
I shall bring the holidays from database where I keep my holiday records.
Thanks in advanced.
A longer time ago i had to do similar solution for a busines Application.
you might wanna look at http://msdn.microsoft.com/en-us/magazine/dd882520.aspx
i don't think i can sum it up better than this site.
Look at "Figure 8 The RedLetterDays Display". Sounds like the thing you need.
greetings

Displaying entire year in C# WinForm application

Is it possible to display the entire year (not month by month) in MonthCalendar control. If not is there another option or do I have to make my own control. I need to graphically display some events that happen on certain dates or in certain intervals, and I need to display them for entire year so the standard MonthCalendar's display is not applicable in this case.
Yes you can display a maximum of 12 months. Sincerly I've not worked a lot with this control but looking in the msdn in MonthCalendar Members I found the MonthCalendar.SetCalendarDimensions Method that:
Sets the number of columns and rows of months to display.
So you need to do this:
myMonthCalendarControl.SetCalendarDimensions(4, 3);
//I used 4 columns and 3 rows because the product should be not greater than 12

Generate dynamic calendar controls

How to generate dynamic controls based on selecton by user?
I had appeared for one practical test recently where they had the below mentioned requirements
They had 2 calendars (asp.net default).
They had two options (radio button list) : One was "Repeat On" and another "Repeated On"
The Repeat on had 2 drop down :
1) Day Dropdown: It values were: Every, Every Other Day, Every Third Day
2) Duration dropdown: It values were: Day, Month, Week, Year
The Repeated on had 2 drop down :
1) Week: the values were First Week, Second Week, Third Week
2) Day: Sunday, Monday .... Saturday
Now when i click the first calendar's date as say August 10 2010 and second one as January 26 2011, then i wanted that dynamic calendars should be generated that would show the Calendars from August to January (inclusive of both)
For Filter purpose, if i select First Sunday (From REPEATED ON Option) then first sunday of dynamic calendars should be selected. If i select every third day then every 3rd day should be selected (in dynamic generated calendars)
What i did was : Could generate dynamic calendars by creating object of calendar class.. is that right? Plus i searched on google and they show that DayRender Event could be a possible solution but that didn't help...
How to do that? How to generate dynamic calendar?
Please let me know if question is not being understood.
Pass me on code similar to that the least
thanks!
Sounds like what you want to do is set the properties Calendar.SelectedDate and Calendar.VisibleDate.
I'm not sure exactly what you're going for since I don't know what type of control the user will be selecting your Jan 1/Jun 1 dates from, or what the 3rd sunday has to do with that. Is there only one calendar? Please explain a little more if the info below doesn't help you.
I'll paste some VB code from one of my apps, hopefully it will help you out.
Protected Sub calArrival_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles calArrival.SelectionChanged
SetFormDepartureEntry()
lblArrivalDate.Text = calArrival.SelectedDate.ToLongDateString
calDeparture.SelectedDate = calArrival.SelectedDate
calDeparture.VisibleDate = calArrival.SelectedDate
dtSelectedArrival = "1/1/2000"
'Determine if we need to see 2 months to view all possible departure dates.
If (DatePart(DateInterval.Month, calDeparture.SelectedDate) <> _
DatePart(DateInterval.Month, DateAdd(DateInterval.Day, 14, calDeparture.SelectedDate))) Then
calDeparture2.Visible = True
calDeparture2.SelectedDate = Nothing
calDeparture2.VisibleDate = DateAdd(DateInterval.Month, 1, calDeparture.SelectedDate)
Else
calDeparture2.Visible = False
End If
End Sub
OK now that you have posted the details this becomes a different question. You don't know how many calendars you need to so you will probably want to create them in code. I would suggest using a Panel control in your markup to contain all the possible result calendars. Then as you suggested earlier, create new Calendar objects as needed and add them to the "anchor" Panel's Controls collection.
Calendar objCal = new Calendar();
pnlResultsContainer.Controls.Add(objCal);
As far as setting selected days, you can only have one "selected" day per calendar I believe. However you can set the rendering styles, and whether the day is enabled, etc., by handling the Calendar.DayRender event. Maybe someone can help me out on setting up a handler for dynamically created controls in C#? I think it's something like:
objCal.DayRender += AddressOf(DynamicDayRenderHandler());
Please correct if this is not right.
Determining the correct day to set styles on in the handler will be a matter of coding against the DayRenderEventArgs.Day object which is a parameter of the event. I don't know offhand how to find the specific days/intervals you are looking for but it should be possible with a little research in the following articles:
How to: Customize Individual Days in a Calendar Web Server Control
DayRenderEventArgs.Day Property
Hope this helps.

Categories