Disporre i dati orizziontalmente in una tabella
<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<html>
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
int i, j;
DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("impiegati.xml"));
int rowCount = DS.Tables[0].Rows.Count;
int colCount = DS.Tables[0].Columns.Count;
string[,] dataArray = new string[rowCount,colCount];
for (i=0; i<rowCount; i++)
{
for (j=0; j<colCount; j++)
{
if (DS.Tables[0].Rows[i].ItemArray[j] == null)//.Tables[0].Rows[i].Item[j] == null)
dataArray[i,j]="";
else
dataArray[i,j] = DS.Tables[0].Rows[i].ItemArray[j].ToString();
}
}
TableRow r;
TableCell c;
for (j=0; j<colCount; j++)
{
r = new TableRow();
c = new TableCell();
c.Controls.Add(new LiteralControl(DS.Tables[0].Columns[j].ColumnName));
c.VerticalAlign = VerticalAlign.Top;
c.Style["background-color"] = "#ffff00";
r.Cells.Add(c);
for (i=0; i<rowCount; i++)
{
c = new TableCell();
c.Controls.Add(new LiteralControl(dataArray[i,j]));
c.VerticalAlign = VerticalAlign.Top;
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}
</script>
<body>
<form runat="server" ID="Form1">
<asp:Table id="Table1" BorderWidth="1px" Gridlines="Both" runat="server" BackColor="#E0E0E0" BorderColor="Gray" BorderStyle="Inset" CellPadding="1" CellSpacing="0"/>
</form>
</body>
</html>
Scarica il Codice...
Stampa la pagina