Hi amar,
Refer below sample.
HTML
<asp:GridView runat="server" ID="gvDetails"></asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable table1 = new DataTable();
table1.Columns.Add("ID");
table1.Columns.Add("Intial");
table1.Columns.Add("Sal");
table1.Rows.Add(1, "a", 10);
table1.Rows.Add(2, "b", 20);
table1.Rows.Add(3, "c", 30);
table1.Rows.Add(4, "a", 10);
DataTable table2 = new DataTable();
table2.Columns.Add("Dept");
table2.Columns.Add("Fullname");
table2.Columns.Add("Intial");
table2.Rows.Add("Acc", "xyz", "a");
table2.Rows.Add("SW", "abc", "b");
table2.Rows.Add("lab", "a", "c");
DataTable tblResult = new DataTable();
tblResult.Columns.Add("ID");
tblResult.Columns.Add("Fullname");
tblResult.Columns.Add("Sal");
var result = (from tbl1 in table1.AsEnumerable()
join tbl2 in table2.AsEnumerable() on tbl1["Intial"] equals tbl2["Intial"]
select new
{
ID = tbl1["Id"],
Fullname = tbl2["Fullname"],
Sal = tbl1["Sal"]
}).ToList();
foreach (var item in result)
{
tblResult.Rows.Add(item.ID, item.Fullname, item.Sal);
}
gvDetails.DataSource = tblResult;
gvDetails.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) handles Me.Load
Dim table1 As DataTable = New DataTable()
table1.Columns.Add("ID")
table1.Columns.Add("Intial")
table1.Columns.Add("Sal")
table1.Rows.Add(1, "a", 10)
table1.Rows.Add(2, "b", 20)
table1.Rows.Add(3, "c", 30)
table1.Rows.Add(4, "a", 10)
Dim table2 As DataTable = New DataTable()
table2.Columns.Add("Dept")
table2.Columns.Add("Fullname")
table2.Columns.Add("Intial")
table2.Rows.Add("Acc", "xyz", "a")
table2.Rows.Add("SW", "abc", "b")
table2.Rows.Add("lab", "a", "c")
Dim tblResult As DataTable = New DataTable()
tblResult.Columns.Add("ID")
tblResult.Columns.Add("Fullname")
tblResult.Columns.Add("Sal")
Dim result = (From tbl1 In table1.AsEnumerable() _
Join tbl2 In table2.AsEnumerable() On tbl1("Intial") Equals tbl2("Intial") _
Select New With {Key
.ID = tbl1("Id"), Key
.Fullname = tbl2("Fullname"), Key
.Sal = tbl1("Sal")
}).ToList()
For Each item In result
tblResult.Rows.Add(item.ID, item.Fullname, item.Sal)
Next
gvDetails.DataSource = tblResult
gvDetails.DataBind()
End Sub
Screenshot