From asp table to array

I created a table on my client webpage using asp:

<asp:Table ID="Table1" GridLines="Both" HorizontalAlign="Center" BorderWidth="2" Font-Bold="True" Font-Names="Verdana" Font-Size="8pt" CellPadding="15" CellSpacing="0" runat="server"> </asp:Table> 

Using the button I created, I populate the table with an array:

 for (int j=0; j < cells; j++) { TableRow r = new TableRow(); for (int i = 0; i < row+1; i++) { TableCell c = new TableCell(); c.Controls.Add(new LiteralControl (datar[j,i].ToString())); r.Cells.Add(c); } Table1.Rows.Add(r); } 

This code works great to populate a table. Now I need to create another button to send the table to Excel. Does anyone know how to do this, or how to read data from a table and send back to another array?

the user must decide whether he wants to save the data from the table in order to succeed, that’s why create a second “Save information” button to display information

+4
source share
1 answer

Try it. I cannot guarantee 100% for this because I do not have an actual table filled with information to check it, but try this anyway.

  Table t = new Table(); List<string> cells = new List<string>(); foreach (TableRow r in t.Rows) { foreach (TableCell cell in r.Cells) { cells.Add(cell.ToString()); } } String[] array = cells.ToArray(); 

This assumes that we do not need to define a fixed array before we start investing material in it, so to avoid this, I just created an array and converted the list to one. It is software slow. To get the size of the array before hand, just multiply String [TableWidth * TableHeight] and you will have a fixed array of the correct size.

+1
source

All Articles