Hi @Prajakta Patil ,
Below is my demo to use LINQ to get the result in the format you want:
SPList list = web.Lists["Mylist"];
var result = (from SPListItem item in list.Items
orderby item["Manager"]
group item by new {p1= item["Manager"] } into g
select new { managerName=g.Key.p1, total=g.Count() });
foreach (var oitem in result)
{
Console.WriteLine($"Manger {oitem.managerName}:count of list items in A having manager as A is: {oitem.total}");
}
And you could make some changes to item["Manager"]
to get the manager name like this:
var result = (from SPListItem item in list.Items
orderby item["Manager"]
group item by new {p1= item["Manager"].ToString().Substring(item["Manager"].ToString().IndexOf("#")+1) } into g
select new { managerName=g.Key.p1, total=g.Count() });
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.