How we Get the Data Table Unique IDs Rows into another Data Table in c# for ASP.net for Grid View Binding:
finally you can bind dt2 data table to any grid directly..
string[] FinalIDs = { };
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
FinalIDs = IDs.Distinct().ToArray();
int i = 0;
foreach (string Item in FinalIDs)
{
if (i == 0)
{
dt1.DefaultView.RowFilter = "Someid='" + Item + "'";
dt2 = (dt1.DefaultView).ToTable();
}
else
{
dt1.DefaultView.RowFilter = "Someid='" + Item + "'";
dt2.ImportRow((dt1.DefaultView).ToTable().Rows[0]);
}
i++;
}
i = 0;
finally you can bind dt2 data table to any grid directly..
gridView2.DataSource = dt2;
gridView2.DataBind();