I have renderTable, and I add rows and columns to the table as follows:
RenderTable renderTable = new RenderTable(); DataTable dt = GetData(); foreach (DataRow row in dt.Rows) { var header = renderTable.Rows[renderTable.Rows.Count]; header[0].Text = "Column 1"; header[1].Text = "Column 2"; header[2].Text = "Column 3"; header[1].Text = "Column 4"; var data = renderTable.Rows[renderTable.Rows.Count]; data [0].Text = row["col1"].ToString(); // 10 data [1].Text = row["col2"].ToString(); // 11 data [2].Text = row["col3"].ToString(); // 12 data [3].Text = row["col4"].ToString(); // 13 }
This works fine and the table renders like folllows -
Column 1 Column2 Column3 Column4 10 11 12 13
My requirement: now I want to move column 4 to another place, for example, to 2nd place. (this place may vary depending on condition)
Column 1 Column4 Column2 Column3 10 13 11 12
I tried the Insert method, but it does not work for me, since the insert index may change. Is there any rendering table function to move a column to a specified index.
Please offer any alternative, if any.
source share