private DataTable GetEvents() { DataTable dt = new DataTable(); dt.Columns.Add("EventDate",Type.GetType("System.DateTime")); dt.Columns.Add("EventHeader",Type.GetType("System.String")); dt.Columns.Add("EventDescription",Type.GetType("System.String"));
DataRow dr;
// Last Week's Events dr = dt.NewRow(); dr["EventDate"] = DateTime.Now.AddDays(-7); dr["EventHeader"] = "My Last Week's Event 1"; dr["EventDescription"] = "My Last Week's Event 1 Description"; dt.Rows.Add(dr); return dt; } protected void Page_Load(object sender, EventArgs e) { Calendar1.EventDateColumnName = "EventDate"; Calendar1.EventDescriptionColumnName = "EventDescription"; Calendar1.EventHeaderColumnName = "EventHeader";
Calendar1.EventSource = GetEvents(); } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { SelectedDatesCollection theDates = Calendar1.SelectedDates; DataTable dtEvents = Calendar1.EventSource; DataTable dtSelectedDateEvents = dtEvents.Clone(); DataRow dr; foreach(DataRow drEvent in dtEvents.Rows) foreach(DateTime selectedDate in theDates) if ((Convert.ToDateTime(drEvent[Calendar1.EventDateColumnName])).ToShortDateString() == selectedDate.ToShortDateString() ) { dr = dtSelectedDateEvents.NewRow(); dr[Calendar1.EventDateColumnName] = drEvent[Calendar1.EventDateColumnName]; dr[Calendar1.EventHeaderColumnName] = drEvent[Calendar1.EventHeaderColumnName]; dr[Calendar1.EventDescriptionColumnName] = drEvent[Calendar1.EventDescriptionColumnName]; dtSelectedDateEvents.Rows.Add(dr); } gvSelectedDateEvents.DataSource = dtSelectedDateEvents; gvSelectedDateEvents.DataBind();
}
|