Before this I never played that much with ASP.NET Calendar control.. so I decided to give it a shot..& see if requirement can be met.. and to my surprise.. it shaped-up real fast & good by the late afternoon.. in just couple of hours I had this screen up-n-running!!! :D
steps --- 1. created a table (HolidayList) in DB with single field as Holiday Date.
2. drag asp.net calendar control on the form (refer image above.. left middle side.. )
3. get the holiday list collection from HolidayList table (from DB)...
4. Few events which will make the thing going...
a. OnDayRender - this event is fired when a day is getting rendered on calendar.. & gives 'DayRenderEventArgs e', having the day/cell/url for each day which is getting rendered.. all you need is to check the day with the holiday list.. if matched.. change the look & feel of the cell (viz. Table Cell)..
e.Cell.BackColor = System.Drawing.Color.Silver;
e.Cell.ForeColor = System.Drawing.Color.Black;
e.Cell.Font.Bold = true;
b. OnVisibleMonthChanged - fired when month is changed by user.. all we need to do is to get data for this month.. & keep the collection for DayRendering..
c. OnSelectionChanged - fired when date selection is changed by user.. this event gives me the opportunity to capture the selected date and store it in DB (Holiday List table).. refresh the holiday list collection..
5. dragged a ListBox server control to help me with removal of dates from the list.. allowing multiple selection.. and remove button.. simply check for selected dates & remove them from data table (holiday list.. )
foreach (ListItem lstItem in lstHolidays.Items)
{
if (lstItem.Selected)
{
DateTime dt = Convert.ToDateTime(lstItem.Text);
hlfactory.Delete(dt);
}
}
few other supporting operations required (for data insertion/deletion etc.)... & you are done.. it is this simple!!!
 
No comments:
Post a Comment