How to add new column in the existing table at our desired location
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Mohit Jain19 reputationPosted May 25, 2009, 1:52 AM EDT
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.