0

我想画一个有 2 列的表格。第一列将有 2 行,每行分别包含 a 和 b 字母,第二列不包含任何行。这是我的代码。

Public Class trialtable
    Inherits System.Web.UI.Page

    Protected Sub trialtable(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim trial As DataTable
        trial = New DataTable
        Dim tbl As New Table()

        Dim szName As String = ""
        Dim szNumber As String = ""
        Dim szsadasd As String = ""
        tbl.BorderColor = Drawing.Color.Black
        tbl.BorderWidth = 1
        tbl.CellPadding = 0
        tbl.CellSpacing = 0

        For i As Integer = 0 To 1
            Dim tr As New TableRow()
            Dim tc1 As New TableCell()
            Dim tc2 As New TableCell()
            Dim tc3 As New TableCell()
            tc1.Controls.Add(New LiteralControl(szName))
            tc2.Controls.Add(New LiteralControl(szNumber))
            tc3.Controls.Add(New LiteralControl(szsadasd))
            tc1.BorderColor = Drawing.Color.Black
            tc1.BorderWidth = 1
            tc2.BorderColor = Drawing.Color.Black
            tc2.BorderWidth = 1
            tc3.BorderColor = Drawing.Color.Black
            tc3.BorderWidth = 1
            tr.Cells.Add(tc1)
            tr.Cells.Add(tc2)
            tr.Cells.Add(tc3)
            tbl.Controls.Add(tr)
        Next
        Me.Controls.Add(tbl)
    End Sub
End Class
4

1 回答 1

0

为了将值a放在第一行b的第一个单元格和第二行的第一个单元格中,并且在两行的第二个单元格中都没有任何内容,请替换以下代码行...

tc1.Controls.Add(New LiteralControl(szName))
tc2.Controls.Add(New LiteralControl(szNumber))

使用以下代码...

If i = 0 Then
    tc1.Controls.Add(New LiteralControl("a"))
Else
    tc1.Controls.Add(New LiteralControl("b"))
End If
tc2.Controls.Add(New LiteralControl(" "))
于 2012-08-22T14:08:15.693 回答