ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Highlight date range in Calendar control based on database date using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="Tevin"> Tevin</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:Calendar ID=&#34;Calendar1&#34; OnDayRender=&#34;CalendarDayRender&#34; runat=&#34;server&#34;&gt;&lt;/asp:Calendar&gt;</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void CalendarDayRender(object sender, DayRenderEventArgs e) { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn(&#34;FromDate&#34;, typeof(DateTime)), new System.Data.DataColumn(&#34;ToDate&#34;, typeof(DateTime)) }); dt.Rows.Add(DateTime.Now.AddDays(-3), DateTime.Now); dt.Rows.Add(DateTime.Now.AddDays(9), DateTime.Now.AddDays(15)); dt.Rows.Add(DateTime.Now.AddMonths(1).AddDays(1), DateTime.Now.AddMonths(1).AddDays(5)); if (dt.Rows.Count &gt; 0) { foreach (System.Data.DataRow dr in dt.Rows) { DateTime fromDate = (DateTime)dr[&#34;FromDate&#34;]; DateTime toDate = (DateTime)dr[&#34;ToDate&#34;]; if (e.Day.Date &gt;= fromDate &amp;&amp; e.Day.Date &lt;= toDate) { e.Cell.BackColor = System.Drawing.Color.Red; e.Cell.ForeColor = System.Drawing.Color.White; e.Cell.Font.Bold = true; } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub CalendarDayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Dim dt As Data.DataTable = New Data.DataTable() dt.Columns.AddRange(New Data.DataColumn() { New Data.DataColumn(&#34;FromDate&#34;, GetType(DateTime)), New Data.DataColumn(&#34;ToDate&#34;, GetType(DateTime))}) dt.Rows.Add(DateTime.Now.AddDays(-3), DateTime.Now) dt.Rows.Add(DateTime.Now.AddDays(9), DateTime.Now.AddDays(15)) dt.Rows.Add(DateTime.Now.AddMonths(1).AddDays(1), DateTime.Now.AddMonths(1).AddDays(5)) If dt.Rows.Count &gt; 0 Then For Each dr As Data.DataRow In dt.Rows Dim fromDate As DateTime = CType(dr(&#34;FromDate&#34;), DateTime) Dim toDate As DateTime = CType(dr(&#34;ToDate&#34;), DateTime) If e.Day.Date &gt;= fromDate AndAlso e.Day.Date &lt;= toDate Then e.Cell.BackColor = System.Drawing.Color.Red e.Cell.ForeColor = System.Drawing.Color.White e.Cell.Font.Bold = True End If Next End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/sIVptN9.jpg" alt="" width="272" height="212" /></p>https://www.aspforums.net:443/Threads/184938/Highlight-date-range-in-Calendar-control-based-on-database-date-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/184938/Highlight-date-range-in-Calendar-control-based-on-database-date-using-C-and-VBNet-in-ASPNet/Thu, 08 Aug 2019 04:46:53 GMT