imports system
imports system.web.ui
imports system.web.ui.webControls

Public Class ex31VB
    Inherits System.Web.UI.Page
    Protected WithEvents Table1 As System.Web.UI.WebControls.Table
    Protected WithEvents Btn As System.Web.UI.WebControls.Button
    Protected WithEvents Button1 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Button2 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Button3 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Button4 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents label1 As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        InitializeComponent()
    End Sub

#End Region
    Shared numrows As Integer = 2     '表格的行数
    Shared numcells As Integer = 2      '表格的列数
    Shared Forrows As Integer      '上次改变时表格的行数
    Shared Forcells As Integer      '上次改变时表格的列数

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs)

    End Sub

    Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn.Click
        CreatTable()
    End Sub
    Function CreatTable() '创建表格函数
        If Numrows < 1 Or Numrows > 10 Then
            label1.Text = "表格行的范围为1－10！"
            numrows = Forrows
        ElseIf Numcells < 1 Or Numcells > 6 Then
            label1.Text = "表格列的范围为1－6！"
            numcells = Forcells
        Else
            label1.Text = ""
        End If

        Dim j As Integer
        For j = 0 To numrows - 1
            Dim r As New TableRow()
            Dim i As Integer
            For i = 0 To numcells - 1
                Dim c As New TableCell()
                c.Controls.Add(New LiteralControl("第 " & (j + 1).ToString() & "行，第 " & (i + 1).ToString() & "列"))
                r.Cells.Add(c)
            Next i
            Table1.Rows.Add(r)
        Next j
        Forrows = numrows
        Forcells = numcells
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        numRows += 1
        CreatTable()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        numcells += 1
        CreatTable()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        numRows -= 1
        CreatTable()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        numcells -= 1
        CreatTable()
    End Sub
End Class
