CODE BEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class innerjoinLinq : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var orderForProducts = from Pro in GetProductList()
join OrderData in GetOrderList()
on Pro.ProductID equals OrderData.ProductID
select new
{
Pro.ProductName,
OrderData.ShipPostalCode,
OrderData.shipCity
};
gvJoin.DataSource = orderForProducts;
gvJoin.DataBind();
}
}
private List<Product>GetProductList()
{
List<Product> ProductList = new List<Product>
{
new Product{ProductID=1, ProductName="Shirt"},
new Product{ProductID=2, ProductName="Pant"},
new Product{ProductID=3, ProductName="Towel"},
new Product{ProductID=4, ProductName="Fabrics"},
new Product{ProductID=5, ProductName="Spary"}
};
return ProductList;
}
private List<Order> GetOrderList()
{
List<Order> ProductOrders = new List<Order>{
new Order{OrderID=1, ProductID=1, ShipPostalCode="1210",shipCity ="Dhaka"},
new Order{OrderID=2, ProductID=5, ShipPostalCode="2201",shipCity ="Chittagong"},
new Order{OrderID=3, ProductID=1, ShipPostalCode="1050",shipCity ="Dinajpur"},
new Order{OrderID=4, ProductID=3, ShipPostalCode="1250",shipCity ="Sylhet"},
new Order{OrderID=5, ProductID=3, ShipPostalCode="1150",shipCity ="Barisal"},
new Order{OrderID=6, ProductID=4, ShipPostalCode="1210",shipCity ="Rangpur"}
};
return ProductOrders;
}
public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
}
public class Order
{
public int OrderID { get; set; }
public int ProductID { get; set; }
public string ShipPostalCode { get; set; }
public string shipCity { get; set; }
}
}
}