How to add new column in the existing table at our desired location
How to add new column in the existing table at our desired location
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mohit JainPosted May 25, 2009, 5:52 AM
Hi Puroshottam,
To create the columns in a table dynamically, you will have to use TableHeaderCell, TableHeaderRow, TableCell and TableHeaderCell classes. As in the following code I have created 2 rows with 2 columns dynamically. To put the cells at the specified location you can use AddAt method.
TableHeaderCell
hcell1 = new TableHeaderCell();hcell1.Text =
"Column1"; TableHeaderCell hcell2 = new TableHeaderCell();hcell2.Text =
"Column2"; TableHeaderRow headerrow = new TableHeaderRow();headerrow.Cells.AddAt(0, hcell1);
headerrow.Cells.AddAt(1, hcell2);
Table1.Rows.Add(headerrow);
TableCell cell1 = new TableCell();cell1.Text =
"Value1"; TableCell cell2 = new TableCell();cell2.Text =
"Value2"; TableRow row = new TableRow();row.Cells.AddAt(0, cell1);
row.Cells.AddAt(1, cell2);
Table1.Rows.Add(row);
Hope this help.