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.Count number of alternate Monday between two Dates in ASP.Net using C# and VB.Net<p>Hey <a class="username" rel="democloud"> democloud</a>,</p> <p>Please refer below sample and refer below article.</p> <h1 class="header"><a title="AJAX Calendar Extender control with Time in ASP.Net'a" href="https://www.aspsnippets.com/Articles/AJAX-Calendar-Extender-control-with-Time-in-ASPNet.aspx">AJAX Calendar Extender control with Time in ASP.Net</a></h1> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script src=&#34;Scripts/jquery-1.4.1.min.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;script src=&#34;Scripts/jquery.dynDateTime.min.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;script src=&#34;Scripts/calendar-en.min.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;link href=&#34;Styles/calendar-blue.css&#34; rel=&#34;stylesheet&#34; type=&#34;text/css&#34; /&gt; &lt;script type=&#34;text/javascript&#34;&gt; &nbsp;&nbsp;&nbsp; $(document).ready(function () { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(&#34;.test&#34;).dynDateTime({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; showsTime: true, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ifFormat: &#34;%m/%d/%y&#34;, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; daFormat: &#34;%l;%M %p, %e %m, %Y&#34;, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; align: &#34;BR&#34;, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; electric: false, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; singleClick: false, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; displayArea: &#34;.siblings(&#39;.dtcDisplayArea&#39;)&#34;, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; button: &#34;.next()&#34; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }); &nbsp;&nbsp;&nbsp; }); &lt;/script&gt; &lt;div&gt; &nbsp;&nbsp;&nbsp; &lt;asp:TextBox ID=&#34;TextBox1&#34; runat=&#34;server&#34; ReadOnly=&#34;true&#34; class=&#34;test&#34;&gt;&lt;/asp:TextBox&gt; &nbsp;&nbsp;&nbsp; &lt;img src=&#34;calender.png&#34; alt=&#34;blank&#34; /&gt; &nbsp;&nbsp;&nbsp; &lt;asp:TextBox ID=&#34;TextBox2&#34; runat=&#34;server&#34; ReadOnly=&#34;true&#34; class=&#34;test&#34;&gt;&lt;/asp:TextBox&gt; &nbsp;&nbsp;&nbsp; &lt;img src=&#34;calender.png&#34; alt=&#34;blank&#34; /&gt; &nbsp;&nbsp;&nbsp; &lt;asp:Button ID=&#34;btnSave&#34; runat=&#34;server&#34; Text=&#34;Count&#34; OnClick=&#34;btnSave_Click&#34; /&gt; &nbsp;&nbsp;&nbsp; &lt;asp:GridView ID=&#34;gvDayes&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Columns&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:BoundField DataField=&#34;Days&#34; HeaderText=&#34;Days&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:BoundField DataField=&#34;Date&#34; HeaderText=&#34;Date&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Columns&gt; &nbsp;&nbsp;&nbsp; &lt;/asp:GridView&gt; &nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&#34;lblCount&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void btnSave_Click(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; DataTable dt = new DataTable(); &nbsp;&nbsp;&nbsp; dt.Columns.Add(&#34;Days&#34;); &nbsp;&nbsp;&nbsp; dt.Columns.Add(&#34;Date&#34;); &nbsp;&nbsp;&nbsp; DateTime startDate = DateTime.Parse(Request.Form[TextBox1.UniqueID]); ; &nbsp;&nbsp;&nbsp; DateTime endDate = DateTime.Parse(Request.Form[TextBox2.UniqueID]); &nbsp;&nbsp;&nbsp; for (DateTime date = startDate; date &lt;= endDate; date = date.AddDays(1)) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (date.DayOfWeek == DayOfWeek.Monday) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt.Rows.Add(date.DayOfWeek, date); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; IEnumerable&lt;DataRow&gt; result = (from products in dt.AsEnumerable() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select products).Where((c, i) =&gt; i % 2 == 0); &nbsp;&nbsp;&nbsp; DataTable dt1 = dt.Clone(); &nbsp;&nbsp;&nbsp; foreach (DataRow row in result) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dt1.ImportRow(row); &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; lblCount.Text = &#34;Total number of monday in month : &#34; + result.Count().ToString(); &nbsp;&nbsp;&nbsp; gvDayes.DataSource = dt1; &nbsp;&nbsp;&nbsp; gvDayes.DataBind(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) &nbsp;&nbsp;&nbsp;&nbsp;Dim dt As DataTable = New DataTable() &nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(&#34;Days&#34;) &nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(&#34;Date&#34;) &nbsp;&nbsp;&nbsp;&nbsp;Dim startDate As DateTime = DateTime.Parse(Request.Form(TextBox1.UniqueID)) &nbsp;&nbsp;&nbsp;&nbsp;Dim endDate As DateTime = DateTime.Parse(Request.Form(TextBox2.UniqueID)) &nbsp;&nbsp;&nbsp;&nbsp;Dim date1 As DateTime = startDate &nbsp;&nbsp;&nbsp;&nbsp;While date1 &lt;= endDate &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If date1.DayOfWeek = DayOfWeek.Monday Then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(date1.DayOfWeek, date1) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;date1 = date1.AddDays(1) &nbsp;&nbsp;&nbsp;&nbsp;End While &nbsp;&nbsp;&nbsp;&nbsp;Dim result As IEnumerable(Of DataRow) = (From products In dt.AsEnumerable() Select products).Where(Function(c, i) i Mod 2 = 0) &nbsp;&nbsp;&nbsp;&nbsp;Dim dt1 As DataTable = dt.Clone() &nbsp;&nbsp;&nbsp;&nbsp;For Each row As DataRow In result &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt1.ImportRow(row) &nbsp;&nbsp;&nbsp;&nbsp;Next &nbsp;&nbsp;&nbsp;&nbsp;lblCount.Text = &#34;Total number of monday in month : &#34; &amp; result.Count().ToString() &nbsp;&nbsp;&nbsp;&nbsp;gvDayes.DataSource = dt1 &nbsp;&nbsp;&nbsp;&nbsp;gvDayes.DataBind() End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><strong><img src="https://i.imgur.com/5t2hhZl.gif" alt="" width="251" height="315" /></strong></p>https://www.aspforums.net:443/Threads/136945/Count-number-of-alternate-Monday-between-two-Dates-in-ASPNet-using-C-and-VBNet/https://www.aspforums.net:443/Threads/136945/Count-number-of-alternate-Monday-between-two-Dates-in-ASPNet-using-C-and-VBNet/Mon, 31 Dec 2018 06:42:37 GMT