Hi AjayP,
Here i have used Northwind Database. The download and install instructions are provided in the following article.
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string ContactName = "Maria";
string Country = "Austria";
string ShipCity = "Berlin";
CustomersJoinDataContext ctx = new CustomersJoinDataContext();
var strQuery = from customer in ctx.Customers
join order in ctx.Orders
on customer.CustomerID equals order.CustomerID
select new
{
CustomerID = customer.CustomerID,
CompanyName = customer.CompanyName,
ContactName = customer.ContactName,
ContactTitle = customer.ContactTitle,
Address = customer.Address,
City = customer.City,
Region = customer.Region,
PostalCode = customer.PostalCode,
Country = customer.Country,
Phone = customer.Phone,
Fax = customer.Fax,
OrderID = order.OrderID,
EmployeeID = order.EmployeeID,
OrderDate = order.OrderDate,
RequiredDate = order.RequiredDate,
ShippedDate = order.ShippedDate,
ShipVia = order.ShipVia,
Freight = order.Freight,
ShipName = order.ShipName,
ShipAddress = order.ShipAddress,
ShipCity = order.ShipCity,
ShipRegion = order.ShipRegion,
ShipPostalCode = order.ShipPostalCode,
ShipCountry = order.ShipCountry
};
if (!string.IsNullOrEmpty(ContactName))
{
strQuery = strQuery.Where(x => x.ContactName == ContactName);
}
if (!string.IsNullOrEmpty(Country))
{
strQuery = strQuery.Where(x => x.Country == Country);
}
if (!string.IsNullOrEmpty(ShipCity))
{
strQuery = strQuery.Where(x => x.ShipCity == ShipCity);
}
GridView1.DataSource = strQuery;
GridView1.DataBind();
}
}
HTML
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
Output
CustomerID | CompanyName | ContactName | ContactTitle | Address | City | Region | PostalCode | Country | Phone | Fax | OrderID | EmployeeID | OrderDate | RequiredDate | ShippedDate | ShipVia | Freight | ShipName | ShipAddress | ShipCity | ShipRegion | ShipPostalCode | ShipCountry |
ALFKI |
Alfreds Futterkiste |
Maria |
Sales Representative |
Obere Str. 57 |
Boise |
|
12209 |
Austria |
030-0074321 |
030-0076545 |
10643 |
6 |
8/25/1997 12:00:00 AM |
9/22/1997 12:00:00 AM |
9/2/1997 12:00:00 AM |
1 |
29.4600 |
Alfreds Futterkiste |
Obere Str. 57 |
Berlin |
|
12209 |
Germany |
ALFKI |
Alfreds Futterkiste |
Maria |
Sales Representative |
Obere Str. 57 |
Boise |
|
12209 |
Austria |
030-0074321 |
030-0076545 |
10692 |
4 |
10/3/1997 12:00:00 AM |
10/31/1997 12:00:00 AM |
10/13/1997 12:00:00 AM |
2 |
61.0200 |
Alfred's Futterkiste |
Obere Str. 57 |
Berlin |
|
12209 |
Germany |
ALFKI |
Alfreds Futterkiste |
Maria |
Sales Representative |
Obere Str. 57 |
Boise |
|
12209 |
Austria |
030-0074321 |
030-0076545 |
10702 |
4 |
10/13/1997 12:00:00 AM |
11/24/1997 12:00:00 AM |
10/21/1997 12:00:00 AM |
1 |
23.9400 |
Alfred's Futterkiste |
Obere Str. 57 |
Berlin |
|
12209 |
Germany |
ALFKI |
Alfreds Futterkiste |
Maria |
Sales Representative |
Obere Str. 57 |
Boise |
|
12209 |
Austria |
030-0074321 |
030-0076545 |
10835 |
1 |
1/15/1998 12:00:00 AM |
2/12/1998 12:00:00 AM |
1/21/1998 12:00:00 AM |
3 |
69.5300 |
Alfred's Futterkiste |
Obere Str. 57 |
Berlin |
|
12209 |
Germany |
ALFKI |
Alfreds Futterkiste |
Maria |
Sales Representative |
Obere Str. 57 |
Boise |
|
12209 |
Austria |
030-0074321 |
030-0076545 |
10952 |
1 |
3/16/1998 12:00:00 AM |
4/27/1998 12:00:00 AM |
3/24/1998 12:00:00 AM |
1 |
40.4200 |
Alfred's Futterkiste |
Obere Str. 57 |
Berlin |
|
12209 |
Germany |
ALFKI |
Alfreds Futterkiste |
Maria |
Sales Representative |
Obere Str. 57 |
Boise |
|
12209 |
Austria |
030-0074321 |
030-0076545 |
11011 |
3 |
4/9/1998 12:00:00 AM |
5/7/1998 12:00:00 AM |
4/13/1998 12:00:00 AM |
1 |
1.2100 |
Alfred's Futterkiste |
Obere Str. 57 |
Berlin |
|
12209 |
Germany |