Hi rajeshg12,
Check this sample. now take its reference.
HTML
<asp:GridView runat="server" ID="gvDetails" />
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.AddRange(new DataColumn[] {
new DataColumn("Column1"),
new DataColumn("Column2"),
new DataColumn("Column3"),
new DataColumn("Column4") });
dt.Rows.Add("Nephrology", "2010", "1,3", "SDTM specs,Table prog/QC");
dt.Rows.Add("Nephrology", "2010", "2,ISE", "ADaM specs,SDTM prog/QC");
dt.Rows.Add("Nephrology1", "2011", "2,ISE", "ADaM specs,SDTM prog/QC");
DataTable dtRsult = dt.Clone();
var distinctRows = dt.DefaultView.ToTable(true, "Column1").Rows.OfType<DataRow>().Select(k => k[0] + "").ToArray();
foreach (string name in distinctRows)
{
var rows = dt.Select("Column1 = '" + name + "'");
string column3 = "";
string column4 = "";
foreach (DataRow row in rows)
{
column3 += row["Column3"] + ",";
column4 += row["Column4"] + ",";
}
column3 = column3.Trim(',');
column4 = column4.Trim(',');
dtRsult.Rows.Add(rows[0]["Column1"], rows[0]["Column2"], column3, column4);
column3 = "";
column4 = "";
}
gvDetails.DataSource = dtRsult;
gvDetails.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.AddRange(New DataColumn() {
New DataColumn("Column1"),
New DataColumn("Column2"),
New DataColumn("Column3"),
New DataColumn("Column4")})
dt.Rows.Add("Nephrology", "2010", "1,3", "SDTM specs,Table prog/QC")
dt.Rows.Add("Nephrology", "2010", "2,ISE", "ADaM specs,SDTM prog/QC")
dt.Rows.Add("Nephrology1", "2011", "2,ISE", "ADaM specs,SDTM prog/QC")
Dim dtRsult As DataTable = dt.Clone()
Dim distinctRows = dt.DefaultView.ToTable(True, "Column1").Rows.OfType(Of DataRow)().Select(Function(k) k(0) & "").ToArray()
For Each name As String In distinctRows
Dim rows = dt.Select("Column1 = '" & name & "'")
Dim column3 As String = ""
Dim column4 As String = ""
For Each row As DataRow In rows
column3 += row("Column3") & ","
column4 += row("Column4") & ","
Next
column3 = column3.Trim(","c)
column4 = column4.Trim(","c)
dtRsult.Rows.Add(rows(0)("Column1"), rows(0)("Column2"), column3, column4)
column3 = ""
column4 = ""
Next
gvDetails.DataSource = dtRsult
gvDetails.DataBind()
End Sub
Screenshot