Introduction: In this Article we'll see how to use the Calendar Control in a Webform.
The Calendar Control shows the Current Month Dates and the Dates also of the previous and Next Month.
So,
The Database Data is stored as:
<
In Page_Load
In Calendar1_PreRender
In Calendar1_SelectionChanged
C#SqlConnection mycn;SqlDataAdapter myda;DataSet ds = new DataSet ();DataSet dsSelDate;String strConn;private void Page_Load(object sender, System.EventArgs e){// Put user code to initialize the page herestrConn="Data Source=localhost;uid=sa;pwd=;Initial Catalog=northwind";mycn = new SqlConnection(strConn);myda = new SqlDataAdapter ("Select * FROM EventsTable", mycn);myda.Fill (ds,"Table");}protected void CalendarDRender(object sender ,System.Web.UI.WebControls.DayRenderEventArgs e ) {// If the month is CurrentMonthif (! 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 Dateselse{e.Cell.Text = "";}}private void Calendar1_SelectionChanged(object sender, System.EventArgs e){myda = new SqlDataAdapter("Select * from EventsTable where EventDate='" + Calendar1.SelectedDate.ToString() + "'", mycn);dsSelDate = new DataSet();myda.Fill(dsSelDate, "AllTables");if (dsSelDate.Tables[0].Rows.Count == 0 ){DataGrid1.Visible = false;}else{DataGrid1.Visible = true;DataGrid1.DataSource = dsSelDate;DataGrid1.DataBind (); }}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: