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.Linq query to Count record in each Group using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="v@run"> v@run</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;gvIdCount&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Id&#34; HeaderText=&#34;Id&#34; /&gt; &lt;asp:BoundField DataField=&#34;Count&#34; HeaderText=&#34;Count&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&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; using NorthwindModel;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports NorthwindModel 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 Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { NorthwindEntities enity = new NorthwindEntities(); var result = from order in enity.Orders join employee in enity.Employees on order.EmployeeID equals employee.EmployeeID into details group details by order.EmployeeID into grouped select new { EmployeeID = grouped.Key, Count = grouped.Count() }; DataTable dt = new DataTable(); dt.Columns.Add(&#34;Id&#34;); dt.Columns.Add(&#34;Count&#34;); foreach (var item in result) { dt.Rows.Add(item.EmployeeID, item.Count); } this.gvIdCount.DataSource = dt; this.gvIdCount.DataBind(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim enity As NorthwindEntities = New NorthwindEntities() Dim result = From order In enity.Orders Join employee In enity.Employees On order.EmployeeID Equals employee.EmployeeID Group order By key = New With {.EmployeeID = order.EmployeeID} Into Group Select New With {.EmployeeID = key.EmployeeID, .Count = Group.Count()} Dim dt As DataTable = New DataTable() dt.Columns.Add(&#34;Id&#34;) dt.Columns.Add(&#34;Count&#34;) For Each item In result dt.Rows.Add(item.EmployeeID, item.Count) Next Me.gvIdCount.DataSource = dt Me.gvIdCount.DataBind() End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/4u8tTmr.jpg" alt="" width="249" height="442" /></p>https://www.aspforums.net:443/Threads/728625/Linq-query-to-Count-record-in-each-Group-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/728625/Linq-query-to-Count-record-in-each-Group-using-C-and-VBNet-in-ASPNet/Fri, 17 May 2019 07:18:48 GMT