Hey yogesjoshi,
Please refer below sample.
HTML
<table>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" />
</td>
<td>
<asp:GridView ID="GridView2" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:GridView ID="GridView3" Caption="<b>Output</b>" runat="server" />
</td>
</tr>
</table>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Department");
dt.Columns.Add("name");
dt.Columns.Add("marks");
dt.Rows.Add("it", "abc", "80");
dt.Rows.Add("cs", "xyz", "67");
dt.Rows.Add("mec", "abc", "76");
dt.Rows.Add("ece", "xyz", "73");
dt.Rows.Add("it", "ab", "85");
DataTable dt2 = new DataTable();
dt2.Columns.Add("Department");
dt2.Columns.Add("name");
dt2.Columns.Add("marks");
dt2.Rows.Add("it", "abc", "80");
dt2.Rows.Add("cs", "xyz", "50");
dt2.Rows.Add("mec", "abc", "76");
dt2.Rows.Add("eee", "abc", "40");
//Multiple Condition
var dt1result = dt.AsEnumerable();
var dt2result = dt2.AsEnumerable();
var result = (from dt1Row in dt1result
from dt2Row in dt2result
where dt1Row["name"] == dt2Row["name"]
&& dt1Row["Department"] == dt2Row["Department"]
&& Convert.ToInt32(dt1Row["marks"]) == Convert.ToInt32(dt2Row["marks"])
select new
{
name = dt1Row.Field<string>("name"),
marks = dt1Row.Field<string>("marks"),
department = dt2Row.Field<string>("Department")
});
GridView1.DataSource = dt;
GridView1.DataBind();
GridView2.DataSource = dt2;
GridView2.DataBind();
GridView3.DataSource = result;
GridView3.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim dt As DataTable = New DataTable()
dt.Columns.Add("Department")
dt.Columns.Add("name")
dt.Columns.Add("marks")
dt.Rows.Add("it", "abc", "80")
dt.Rows.Add("cs", "xyz", "67")
dt.Rows.Add("mec", "abc", "76")
dt.Rows.Add("ece", "xyz", "73")
dt.Rows.Add("it", "ab", "85")
Dim dt2 As DataTable = New DataTable()
dt2.Columns.Add("Department")
dt2.Columns.Add("name")
dt2.Columns.Add("marks")
dt2.Rows.Add("it", "abc", "80")
dt2.Rows.Add("cs", "xyz", "50")
dt2.Rows.Add("mec", "abc", "76")
dt2.Rows.Add("eee", "abc", "40")
Dim dt1result = dt.AsEnumerable()
Dim dt2result = dt2.AsEnumerable()
Dim result = (From dt1Row In dt1result From dt2Row In dt2result Where dt1Row("name") = dt2Row("name") AndAlso dt1Row("Department") = dt2Row("Department") AndAlso Convert.ToInt32(dt1Row("marks")) = Convert.ToInt32(dt2Row("marks")) Select New With {Key .name = dt1Row.Field(Of String)("name"), Key .marks = dt1Row.Field(Of String)("marks"), Key .department = dt2Row.Field(Of String)("Department")})
GridView1.DataSource = dt
GridView1.DataBind()
GridView2.DataSource = dt2
GridView2.DataBind()
GridView3.DataSource = result
GridView3.DataBind()
End Sub
Screenshot