Mega Code Archive

 
Categories / ASP.Net Tutorial / ASP Net Controls
 

Appointment based on Calendar (C#)

File: Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Appointment" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Untitled Page</title> </head> <body>     <form id="form1" runat="server">     <div>             <tr>                 <td>                     Choose day:<br />                     <asp:Calendar ID="MyCalendar"                                    runat="server"                                    OnDayRender="MyCalendar_DayRender"                                    OnSelectionChanged="MyCalendar_SelectionChanged">                     </asp:Calendar>                 </td>                 <td >                     Choose time:<br />                     <asp:ListBox ID="lstTimes"                                   runat="server"                                   Height="168px"                                   Width="136px"></asp:ListBox></td>             </tr>     </div>             </form> </body> </html> File: Default.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Appointment : System.Web.UI.Page {     protected void MyCalendar_SelectionChanged(object sender, EventArgs e)     {         lstTimes.Items.Clear();         switch (MyCalendar.SelectedDate.DayOfWeek)         {             case DayOfWeek.Monday:                 lstTimes.Items.Add("10:00");                 lstTimes.Items.Add("10:30");                 lstTimes.Items.Add("11:00");                 break;             default:                 lstTimes.Items.Add("10:00");                 lstTimes.Items.Add("10:30");                 lstTimes.Items.Add("11:00");                 lstTimes.Items.Add("11:30");                 lstTimes.Items.Add("12:00");                 lstTimes.Items.Add("12:30");                 break;         }     }     protected void MyCalendar_DayRender(object sender, DayRenderEventArgs e)     {         if (e.Day.Date.Day == 28 && e.Day.Date.Month == 2)         {             e.Cell.BackColor = System.Drawing.Color.Yellow;             Label lbl = new Label();             lbl.Text = "<br/>My Birthday!";             e.Cell.Controls.Add(lbl);         }         if (e.Day.Date.Year > 2000)         {             e.Day.IsSelectable = false;         }     } }