<%@ Page Language="VB" %>
<html>
<title>第二十二例 Table控件的使用</title>
<head>
   <script runat="server">
         Dim Shared numrows As Integer = 2	'表格的行数
         Dim Shared numcells As Integer = 2 	'表格的列数
	 Dim Shared Forrows As Integer		'上次改变时表格的行数
	 Dim Shared Forcells As Integer		'上次改变时表格的列数

      Sub Sbt(sender As Object, e As EventArgs)
	   CreatTable
      End Sub
      Sub Submit1(sender As Object, e As EventArgs)
	   numRows+=1
	   CreatTable
      End Sub
      Sub Submit2(sender As Object, e As EventArgs)
	   numcells+=1
	   CreatTable
      End Sub
      Sub Submit3(sender As Object, e As EventArgs)
	   numRows-=1
	   CreatTable
      End Sub
      Sub Submit4(sender As Object, e As EventArgs)
	   numcells-=1
	   CreatTable
      End Sub

      Function CreatTable() '创建表格函数
	 If Numrows < 1 Or Numrows > 10 then
		Label1.text="表格行的范围为1－10！"
		numrows = Forrows
	 Else If 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

   </script>
</head>
<body>
   <form runat="server">
      <h3><font face="Verdana">第二十二例 Table控件的使用</font></h3>

      	<asp:Table id="Table1" Font-Name="Verdana" Font-Size="8pt" CellPadding="5" CellSpacing="0" BorderWidth="1" Gridlines="Both" runat="server"/>
	<br>
	<asp:Button id="Btn" runat="server" OnClick="Sbt" text="创建表格"/>
	<asp:LinkButton id="Button1" runat="server" Onclick="Submit1">新增一行</asp:LinkButton>
	<asp:LinkButton id="Button2" runat="server" Onclick="Submit2">新增一列</asp:LinkButton>
	<asp:LinkButton id="Button3" runat="server" Onclick="Submit3">删除一行</asp:LinkButton>
	<asp:LinkButton id="Button4" runat="server" Onclick="Submit4">删除一列</asp:LinkButton>
	<br>
	<asp:Label id="label1" runat="server" Font-Size="15pt"/>
   </form>
</body>
</html>