Please refer below sample:
HTML
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Customer Ids" DataField="CustomerIds" />
<asp:BoundField HeaderText="Country" DataField="Country" />
<asp:BoundField HeaderText="Count of cities" DataField="Count_of_cities" />
</Columns>
</asp:GridView>
</div>
Namespace
using System.Linq;
using LINQ;
C#
protected void BindGrid()
{
using (DataClassesDataContext dc = new DataClassesDataContext())
{
var res = from c in dc.Customers
group c by new { c.Country } into g
select new
{
Country = g.Key.Country,
CustomerIds = string.Join(",", g.Select(c => c.CustomerID)),
Count_of_cities = g.Select(c => c.City).Count()
};
GridView1.DataSource = res.ToList();
GridView1.DataBind();
}
}
Screenshot