Tags : Festival Names,Calendar Control,Importance of the day,Asp.Net,C#.Net,SQL Server.
Hi Friends,In this article i would like to explain how to display Festival Names on Calender control in ASP.Net.
* For this i took 1 Calendar control on to the page.
* I created a table with name(Holidays) in SQL Server 2005 & fields are HolidayName,HolidayDate.
* Please find the below table once :
* Then find the code for Calender_DayRender event :
Source Code :
Default.aspx.cs :
Hi Friends,In this article i would like to explain how to display Festival Names on Calender control in ASP.Net.
* For this i took 1 Calendar control on to the page.
* I created a table with name(Holidays) in SQL Server 2005 & fields are HolidayName,HolidayDate.
* Please find the below table once :
* Then find the code for Calender_DayRender event :
Source Code :
Default.aspx.cs :
1. using System;
2. using System.Configuration;
3. using System.Data;
4. using System.Linq;
5. using System.Web;
6. using System.Web.Security;
7. using System.Web.UI;
8. using System.Web.UI.HtmlControls;
9. using System.Web.UI.WebControls;
10. using System.Web.UI.WebControls.WebParts;
11. using System.Xml.Linq;
12. using System.Data.SqlClient;
13. public partial class _Default : System.Web.UI.Page
14. {
15. SqlConnection con;
16. protected void Page_Load(object sender, EventArgs e)
17. {
18. con = new SqlConnection(ConfigurationManager.ConnectionStrings["DotnetGuruConnectionString"].ConnectionString);
19. }
20. protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
21. {
22. CalendarDay day = (CalendarDay)e.Day;
23. SqlCommand cmd = new SqlCommand("select HolidayName,HolidayDate from Holidays", con);
24. con.Open();
25. SqlDataReader dr = cmd.ExecuteReader();
26.
27. while (dr.Read())
28. {
29. if (day.Date.ToString() == dr["HolidayDate"].ToString())
30. {
31. TableCell cell = (TableCell)e.Cell;
32. string s1 = dr["HolidayName"].ToString();
33. if (s1 != null)
34. {
35. cell.BackColor = System.Drawing.Color.LightGray;
36. cell.Controls.Add(new LiteralControl("
37. " + s1));
38. }
39.
40. }
41.
42. }
43. con.Close();
44. }
45. }
Default.aspx :
1. <FORM id=form1 runat="server">
2. <DIV>
3.
4. <ASP:CALENDAR id=Calendar1 size="8pt" width="300px" runat="server" showgridlines="True" height="200px" forecolor="#663399" names="Verdana" daynameformat="Shortest" borderwidth="1px" bordercolor="#FFCC66" backcolor="#FFFFCC" ondayrender="Calendar1_DayRender">
5. <SELECTEDDAYSTYLE backcolor="#CCCCFF" bold="True">
6. <SELECTORSTYLE backcolor="#FFCC66">
7. <TODAYDAYSTYLE forecolor="White" backcolor="#FFCC66">
8. <OTHERMONTHDAYSTYLE forecolor="#CC9966">
9. <NEXTPREVSTYLE size="9pt" forecolor="#FFFFCC">
10. <DAYHEADERSTYLE height="1px" backcolor="#FFCC66" bold="True">
11. <TITLESTYLE size="9pt" forecolor="#FFFFCC" backcolor="#990000" bold="True">
12. </TITLESTYLE>
13.
14. </DAYHEADERSTYLE></NEXTPREVSTYLE></OTHERMONTHDAYSTYLE></TODAYDAYSTYLE></SELECTORSTYLE></SELECTEDDAYSTYLE></ASP:CALENDAR></DIV>
15. </FORM>