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.Bind Events in ASP.Net Calendar control from Database using C# and VB.Net<p>Hi&nbsp;<a class="username" rel="nauna">nauna,</a></p> <p>Check this example. Now please take its reference and correct your code.</p> <p>You have to use&nbsp;Calendar <strong>OnDayRender</strong> event to change the cell value.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:Calendar ID=&#34;Calendar1&#34; runat=&#34;server&#34; Width=&#34;500px&#34; BorderColor=&#34;Red&#34; ForeColor=&#34;#663399&#34; OnDayRender=&#34;Calendar1_DayRender&#34; ShowGridLines=&#34;True&#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">private System.Data.DataTable GetData() { System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add(&#34;Date&#34;); dt.Columns.Add(&#34;Desc&#34;); dt.Rows.Add(&#34;01/July/2019 &#34;, &#34;party time&#34;); dt.Rows.Add(&#34;02/July/2019&#34;, &#34;holiday&#34;); dt.Rows.Add(&#34;30/June/2019&#34;, &#34;holiday&#34;); dt.Rows.Add(&#34;15/August/2019&#34;, &#34;holiday&#34;); return dt; } protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) { System.Data.DataTable dt = GetData(); foreach (System.Data.DataRow row in dt.Rows) { if (Convert.ToDateTime(e.Day.Date) == Convert.ToDateTime(row[&#34;Date&#34;])) { e.Cell.Controls.Add(new Label { Text = &#34;&lt;br/&gt;&#34; }); e.Cell.Controls.Add(new Label { Text = row[&#34;Desc&#34;].ToString() }); } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private Function GetData() As Data.DataTable Dim dt As Data.DataTable = New Data.DataTable() dt.Columns.Add(&#34;Date&#34;) dt.Columns.Add(&#34;Desc&#34;) dt.Rows.Add(&#34;01/July/2019 &#34;, &#34;party time&#34;) dt.Rows.Add(&#34;02/July/2019&#34;, &#34;holiday&#34;) dt.Rows.Add(&#34;30/June/2019&#34;, &#34;holiday&#34;) dt.Rows.Add(&#34;15/August/2019&#34;, &#34;holiday&#34;) Return dt End Function Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Dim dt As Data.DataTable = GetData() For Each row As Data.DataRow In dt.Rows If Convert.ToDateTime(e.Day.Date) = Convert.ToDateTime(row(&#34;Date&#34;)) Then e.Cell.Controls.Add(New Label With {.Text = &#34;&lt;br/&gt;&#34;}) e.Cell.Controls.Add(New Label With {.Text = row(&#34;Desc&#34;).ToString()}) End If Next End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/CxCl0Yu.gif" alt="" width="472" height="207" /></span></strong></p>https://www.aspforums.net:443/Threads/132056/Bind-Events-in-ASPNet-Calendar-control-from-Database-using-C-and-VBNet/https://www.aspforums.net:443/Threads/132056/Bind-Events-in-ASPNet-Calendar-control-from-Database-using-C-and-VBNet/Fri, 19 Jul 2019 03:24:53 GMT