asp.net - How to rearrange the table by rows and column in c# -
i have table this
+---------+-----------+-----------+ | product | product-a | product-b | +---------+-----------+-----------+ | | 0 | 1 | +---------+-----------+-----------+ | b | 2 | 3 | +---------+-----------+-----------+ i want rearrange table this
+-----------+-----------+--------+ | product-a | product-b | output | +-----------+-----------+--------+ | | | 0 | +-----------+-----------+--------+ | | b | 1 | +-----------+-----------+--------+ | b | | 2 | +-----------+-----------+--------+ | b | b | 3 | +-----------+-----------+--------+ here have created header this
string columnname = ""; datatable dt1 = new datatable(); (int = 0; < dt.rows.count+1; i++) { string getlist = ""; if (i == 0) { columnname = dt.columns[i].columnname; getlist = dt.rows[i].itemarray[0].tostring(); } else if (i < dt.rows.count) { getlist = dt.rows[i].itemarray[0].tostring(); } else if (i < dt.rows.count+1) { getlist = "output"; } dt1.columns.add(columnname + "-" + getlist, typeof(string)); } i strucking add data in table can give tips add table.
this way write value in data table
(int = 0; < dt.rows.count; i++) { string producta = dt.rows[i].itemarray[0].tostring(); string output = ""; string productb = ""; (int j = 0; j < dt.rows.count; j++) { if (j == 0) { productb = dt.columns[j + 1].columnname; output = dt.rows[i][j+1].tostring(); } else { productb = dt.columns[j+1].columnname; output = dt.rows[i][j+1].tostring(); } dt1.rows.add(producta, productb, output); } }
Comments
Post a Comment