Hi SUJAYS,
Please refer below sample.
HTML
<asp:GridView runat="server" ID="gvCustomers" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName" />
<asp:BoundField DataField="ShipCity" HeaderText="ShipCity" />
<asp:BoundField DataField="OrderId" HeaderText="OrderId" />
</Columns>
</asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
NorthwindEntities enity = new NorthwindEntities();
var result = from c in enity.Customers
join o in enity.Orders on c.CustomerID equals o.CustomerID into ps
from o in ps.DefaultIfEmpty()
select new
{
ContactName = c.CompanyName,
CustomerID = c.CustomerID,
ShipCity = o.ShipCity,
OrderId = (o.OrderID == null ? 0 : o.OrderID)
};
this.gvCustomers.DataSource = result.ToList().Take(5);
this.gvCustomers.DataBind();
}
}
VB.Net
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 c In enity.Customers
Group Join o In enity.Orders On c.CustomerID Equals o.CustomerID
Into ps = Group From o In ps.DefaultIfEmpty()
Select New With {
.ContactName = c.CompanyName,
.CustomerID = c.CustomerID,
.ShipCity = o.ShipCity}
Me.gvCustomers.DataSource = result.ToList().Take(5)
Me.gvCustomers.DataBind()
End If
End Sub
Screenshot