Hi sureshMGR,
Refer below example.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Namespaces
using System.Collections.Generic;
using System.Linq;
using System.Data;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
using (NORTHWINDEntities entities = new NORTHWINDEntities())
{
var result = (from category in entities.Categories
join product in entities.Products on category.CategoryID equals product.CategoryID
select new { category.CategoryID, category.CategoryName, product.ProductName }).ToList();
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("CategoryID"),
new DataColumn("CategoryName"),
new DataColumn("Products") });
List<int> catIds = result.Select(x => x.CategoryID).Distinct().ToList();
foreach (int id in catIds)
{
var data = result.Where(x => x.CategoryID == id);
string products = string.Join(",", result.Where(x => x.CategoryID == id).Select(x => x.ProductName).ToList());
dt.Rows.Add(id, data.Select(x => x.CategoryName).FirstOrDefault(), products);
}
}
}
Screenshot