Here i am explaining how to bind the events from database in asp Calender.For this we need asp Calender in our Web form.

Create the database as follow

Currently i have my database as practice.here i am adding a table as Events.The events table look like as follow.

In this table i have 2 columns
  1. one is Events
  2. one is Date of that events.
Now i am going to bind these events with my calender dates dynamically. For this add a calender control in your asp.net web form.

Click its smart tag for better look and feel of the calender. This will be done as follow.
Increase the height and width of the calender. Go to the .cs page and write the following code in Calender DayRender event.

What is DayRender Event ?
A-calendar DayRender event occurs when each day is created in the control hierarchy of the calendar control. DayRender event is raised when each date cell in the calendar control is created.
  1. protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
  2. {
  3. Literal l = new Literal(); //Creating a literal
  4. l.Visible = true;
  5. l.Text = "<br/>"; //for breaking the line in cell
  6. e.Cell.Controls.Add(l); //adding in all cell
  7. da = new SqlDataAdapter("select * from Events", con);
  8. DataTable dt = new DataTable();
  9. da.Fill(dt);
  10. foreach(DataRow dr in dt.Rows)
  11. {
  12. string x = dr[1].ToString();
  13. if (dr[1].ToString() == e.Day.Date.ToString()) //comparision
  14. {
  15. Label lb = new Label();
  16. lb.Visible = true;
  17. lb.Text = dr[0].ToString();
  18. string a = lb.Text;
  19. e.Cell.Controls.Add(lb);
  20. e.Cell.BackColor = System.Drawing.Color.OrangeRed; // changing cell color
  21. e.Cell.ToolTip = dr[0].ToString(); //adding tooltip
  22. }
  23. }
  24. }
Now it gives the result as follow, binding all events from db table to the Calender.