<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar id="Calendar1" OnDayRender="CalendarDRender" runat="server" BorderWidth="1px" NextPrevFormat="FullMonth" BackColor="White" Width="350px" ForeColor="Black" Height="190px" Font-Size="9pt" Font-Names="Verdana" BorderColor="White"> <todaydaystyle backcolor="#CCCCCC"></todaydaystyle> <nextprevstyle font-size="8pt" font-bold="True" forecolor="#333333" verticalalign="Bottom"></nextprevstyle> <dayheaderstyle font-size="8pt" font-bold="True"></dayheaderstyle> <SelectedDayStyle ForeColor="White" BackColor="#333399"></SelectedDayStyle> <TitleStyle Font-Size="12pt" Font-Bold="True" BorderWidth="4px" ForeColor="#333399" BorderColor="Black" BackColor="White"></TitleStyle> <othermonthdaystyle forecolor="#999999"></othermonthdaystyle> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 23px; POSITION: absolute; TOP: 271px" runat="server" Font-Size="XX-Small" Font-Names="Verdana" Visible="False"> </div> </form> </body> </html>
using System; using System.Drawing; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.OleDb; using System.Data.Sql; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { OleDbConnection mycn; OleDbDataAdapter myda; DataSet ds = new DataSet(); DataSet dsSelDate; string strConn; protected void Page_Load(object sender, EventArgs e) { strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb"; mycn = new OleDbConnection(strConn); myda = new OleDbDataAdapter("Select * FROM EventsTable", mycn); myda.Fill(ds, "EventsTable"); } protected void CalendarDRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { // If the month is CurrentMonth if (!e.Day.IsOtherMonth) { foreach (DataRow dr in ds.Tables[0].Rows) { if ((dr["EventDate"].ToString() != DBNull.Value.ToString())) { DateTime dtEvent = (DateTime)dr["EventDate"]; if (dtEvent.Equals(e.Day.Date)) { e.Cell.BackColor = Color.PaleVioletRed; } } } } //If the month is not CurrentMonth then hide the Dates else { e.Cell.Text = ""; } } private void Calendar1_SelectionChanged(object sender, System.EventArgs e) { myda = new OleDbDataAdapter("Select * from EventsTable where EventDate='" + Calendar1.SelectedDate.ToString() + "'", mycn); dsSelDate = new DataSet(); myda.Fill(dsSelDate, "EventsTable"); if (dsSelDate.Tables[0].Rows.Count == 0) { DataGrid1.Visible = false; } else { DataGrid1.Visible = true; DataGrid1.DataSource = dsSelDate; DataGrid1.DataBind(); } } }
Calendar1.SelectedDate.ToString()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)