J
Joey
Hi There,
I am using an asp table control to display some data, the fields I have are
size,colour,qoh. I have the table structure that I would like to have below
and I have been playing around with datasets and looping to write rows / etc
I'm just having trouble displaying the data the way I want to.
I did have a look at nested datalists, however I don't have the luxury of
time at the moment and I would like to use this method as I'm new to asp
..net as well.
If someone could help me out with the code that would be fantastic, thanks
in advance
Joey
!-- I need to display the data like this
<table width="75%" border="1">
<tr>
<td width="15%">size / colour</td>
<td width="45%">xxs</td>
<td width="13%">xs</td>
<td width="9%">s </td>
<td width="10%">m</td>
<td width="8%">l</td>
</tr>
<tr>
<td>blue</td>
<td>2</td>
<td>10</td>
<td>2</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>green</td>
<td>3</td>
<td>5</td>
<td>4</td>
<td>5</td>
<td>7</td>
</tr>
</table>
Dim dataArray(,) As String
Dim i, j As Integer
Dim myconnection As New OleDb.OleDbConnection()
myconnection = common.connDB()
Dim DS As DataSet = New DataSet()
Dim strColourSql As String = SELECT qoh, shopsales.size,shopsales.shop,
shopsales.style, shopsales.colour,co.colourdesc,sz.sizedesc FROM
shopsales,shops JOIN colours co ON shopsales.colour = co.colour where
shopsales.shop=1 and shopsales.style="'10475RIB1'"
myconnection.Open()
Dim myColourDataAdapter As New OleDb.OleDbDataAdapter(strColourSql,
myconnection)
myColourDataAdapter.Fill(DS, "shopsales")
Dim rowCount As Integer = DS.Tables(0).Rows.Count
Dim colCount As Integer = DS.Tables(0).Columns.Count
ReDim dataArray(rowCount, colCount)
For i = 0 To rowCount - 1
For j = 0 To colCount - 1
If DS.Tables(0).Rows(i).Item(j) Is DBNull.Value Then
dataArray(i, j) = ""
Else
dataArray(i, j) = DS.Tables(0).Rows(i).Item(j)
End If
Next
Next
Dim r As TableRow
Dim c As TableCell
For j = 0 To colCount - 1
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") = "lightblue"
r.Cells.Add(c)
For i = 0 To rowCount - 1
c = New TableCell()
c.Controls.Add(New LiteralControl(dataArray(i, j)))
c.VerticalAlign = VerticalAlign.Top
r.Cells.Add(c)
Next i
Table1.Rows.Add(r)
Next j
I am using an asp table control to display some data, the fields I have are
size,colour,qoh. I have the table structure that I would like to have below
and I have been playing around with datasets and looping to write rows / etc
I'm just having trouble displaying the data the way I want to.
I did have a look at nested datalists, however I don't have the luxury of
time at the moment and I would like to use this method as I'm new to asp
..net as well.
If someone could help me out with the code that would be fantastic, thanks
in advance
Joey
!-- I need to display the data like this
<table width="75%" border="1">
<tr>
<td width="15%">size / colour</td>
<td width="45%">xxs</td>
<td width="13%">xs</td>
<td width="9%">s </td>
<td width="10%">m</td>
<td width="8%">l</td>
</tr>
<tr>
<td>blue</td>
<td>2</td>
<td>10</td>
<td>2</td>
<td>8</td>
<td>9</td>
</tr>
<tr>
<td>green</td>
<td>3</td>
<td>5</td>
<td>4</td>
<td>5</td>
<td>7</td>
</tr>
</table>
Dim dataArray(,) As String
Dim i, j As Integer
Dim myconnection As New OleDb.OleDbConnection()
myconnection = common.connDB()
Dim DS As DataSet = New DataSet()
Dim strColourSql As String = SELECT qoh, shopsales.size,shopsales.shop,
shopsales.style, shopsales.colour,co.colourdesc,sz.sizedesc FROM
shopsales,shops JOIN colours co ON shopsales.colour = co.colour where
shopsales.shop=1 and shopsales.style="'10475RIB1'"
myconnection.Open()
Dim myColourDataAdapter As New OleDb.OleDbDataAdapter(strColourSql,
myconnection)
myColourDataAdapter.Fill(DS, "shopsales")
Dim rowCount As Integer = DS.Tables(0).Rows.Count
Dim colCount As Integer = DS.Tables(0).Columns.Count
ReDim dataArray(rowCount, colCount)
For i = 0 To rowCount - 1
For j = 0 To colCount - 1
If DS.Tables(0).Rows(i).Item(j) Is DBNull.Value Then
dataArray(i, j) = ""
Else
dataArray(i, j) = DS.Tables(0).Rows(i).Item(j)
End If
Next
Next
Dim r As TableRow
Dim c As TableCell
For j = 0 To colCount - 1
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") = "lightblue"
r.Cells.Add(c)
For i = 0 To rowCount - 1
c = New TableCell()
c.Controls.Add(New LiteralControl(dataArray(i, j)))
c.VerticalAlign = VerticalAlign.Top
r.Cells.Add(c)
Next i
Table1.Rows.Add(r)
Next j