You can flip all the entries inside each table of the dataset, Here is the code for FlipDataSet method, is in the code behind file for me. In method FlipDataSet, I am doing flipping of dataset and in BindData, I am binding the first table of it to the DataGrid. This is all:
private void BindData()
{
DataSet ds = this.GetDetail(); // Some DataSet
DataSet new_ds = FlipDataSet(ds); // Flip the DataSet
DataView my_DataView = new_ds.Tables[0].DefaultView;
this.my_DataGrid.DataSource = my_DataView;
this.my_DataGrid.DataBind();
}
public DataSet FlipDataSet(DataSet my_DataSet)
{
DataSet ds = new DataSet();
foreach(DataTable dt in my_DataSet.Tables)
{
DataTable table = new DataTable();
for(int i=0; i<=dt.Rows.Count; i++)
{
table.Columns.Add(Convert.ToString(i));
}
DataRow r;
for(int k=0; k<dt.Columns.Count; k++)
{
r = table.NewRow();
r[0] = dt.Columns[k].ToString();
for(int j=1; j<=dt.Rows.Count; j++)
r[j] = dt.Rows[j-1][k];
}
table.Rows.Add(r);
}
ds.Tables.Add(table);
}
return ds;
}
Old DataSet
| Column1 |
Column2 |
Column3 |
| Neeraj |
Jain |
Carios |
| Tashan |
Yen |
Agknow |
| Andrew |
Ferriere |
Feedback |
Flipped DataSet
| 0 |
1 |
2 |
3 |
| Column1 |
Neeraj |
Tashan |
Andrew |
| Column2 |
Jain |
Yen |
Agknow |
| Column3 |
Carios |
Agknow |
Feedback |