For displaying data in a table,
DataGrid probably is the best choice. However, sometimes you may find it necessary to render your table in a different manner. Say, when you have a database table that has more than twenty fields and only a couple of records, I bet you would want to display all the rows vertically and the columns horizontally. Actually a week ago I stumbled into this problem myself. Checking online, I found some users had the same problem, yet there is not a workable answer ready for sharing. Therefore I present my solution below. It may not be the best answer, but it certainly is quick and simple to me.
For saving the trouble of running SQL scripts to recreate a table, I created a .xml file for use. But the code works perfectly with any database table too.
Briefly speaking, the code first reads a .xml file into a
DataSet, then saves all data into a two dimensional array. The size of array is dynamically decided by the size of the
DataSet table. After the array is populated with data, we build up a table programmatically by adding
<%@ Import Namespace="System.Data" %>
This solution, using XSL to transform XML into HTML in a format desired, is based on a user's suggestion (Thanks). The following is part of the hard-coded XSL file.
<COLGROUP WIDTH="100" ALIGN="CENTER" bgcolor="lavender"></COLGROUP>
To use the XSL file, we need to add XSL reference to the original XML file: