Hi Vasanth057,
I have created sample that full-fill your requirement.
HTML
<asp:GridView runat="server" ID="gvOriginal" Caption="Original" />
<br />
<asp:GridView runat="server" ID="gvDistinct" Caption="Distinct" />
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name", typeof(string)), new DataColumn("Value", typeof(string)) });
dt.Rows.Add("Name1", "123");
dt.Rows.Add("Name1", "123");
dt.Rows.Add("Name2", "321");
gvOriginal.DataSource = dt;
gvOriginal.DataBind();
DataTable distinctTable = dt.AsEnumerable()
.GroupBy(x => x.Field<string>("Name"))
.Select(x => x.First())
.CopyToDataTable();
gvDistinct.DataSource = distinctTable;
gvDistinct.DataBind();
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("Name", GetType(String)), New DataColumn("Value", GetType(String))})
dt.Rows.Add("Name1", "123")
dt.Rows.Add("Name1", "123")
dt.Rows.Add("Name2", "321")
gvOriginal.DataSource = dt
gvOriginal.DataBind()
Dim distinctTable As DataTable = dt.AsEnumerable() _
.GroupBy(Function(x) x.Field(Of String)("Name")) _
.[Select](Function(x) x.First()) _
.CopyToDataTable()
gvDistinct.DataSource = distinctTable
gvDistinct.DataBind()
End If
End Sub
Output
Original
Name | Value |
Name1 |
123 |
Name1 |
123 |
Name2 |
321 |
Distinct
Name | Value |
Name1 |
123 |
Name2 |
321 |