<html>
	<title>第十三例 HtmlTable控件的使用</title>
	<head>
		<script language="VB" runat="server">
		
	public page as Integer
	Public Shared k as Integer =0
      Sub Submit1(sender As Object, e As EventArgs)
	Dim m as Integer =0

	Dim row as Integer =0
	if Select1.Value = "" or Select2.Value = ""
	Message.InnerHtml="输入的行列值不能够为空"
	return
	end if
         Dim numrows As Integer = Convert.ToInt32(Select1.Value)
         Dim numcells As Integer = Convert.ToInt32(Select2.Value)
	if numrows > 50  or numrows < 0  or numcells < 0 or numcells > 8
		
		Message.InnerHtml="不能大于8列50行"
	      return
	end if
	 Dim k as Integer =0
  	 Dim mod1 as Integer =0

	 Message.InnerHtml=""
	 if numrows mod 6 <> 0 
		 mod1=1
	  end if
	 page=numrows \ 6+mod1
	  Message1.InnerHtml="<p><P>按您的输入的数值共有页数 <font color=red size=4>" + Convert.ToString(page) + "</font> 页，转到第："
	StateSelect.Items.Clear
	for  m=0 to page-1 
	StateSelect.Items.Add ((m+1).ToString())
	next
 	Dim j as Integer =0
	 For j = 1 To min(6,numrows)
            Dim r As New HtmlTableRow()

            If row Mod 2 = 1 Then
               r.BgColor = "Gainsboro"
            End If
            row += 1
            Dim i As Integer
            For i = 0 To numcells - 1
               Dim c As New HtmlTableCell()
                c.Controls.Add(new LiteralControl("第" & (j).ToString() & "行" & _
                               "，第" & (i+1).ToString() & "列"))
               r.Cells.Add(c)
            Next i
            Table1.Rows.Add(r)
         Next j

	End Sub

         Sub Submit2(sender As Object, e As EventArgs)

	Dim mod1 as Integer =0
	Dim row as Integer =0
 	 Dim numrows As Integer = Convert.ToInt32(Select1.Value)
         Dim numcells As Integer = Convert.ToInt32(Select2.Value)
	 if numrows mod 6 <> 0 
		 mod1=1
	  end if
	 page=numrows \ 6+mod1

	 Message.InnerHtml=""
	 if k < page-1 
	    k +=1 
	 end if 
	 Dim j as Integer =0
	 For j = k*6+1 To min((k+1)*6,numrows)
            Dim r As New HtmlTableRow()

            If row Mod 2 = 1 Then
               r.BgColor = "Gainsboro"
            End If
            row += 1
            Dim i As Integer
            For i = 0 To numcells - 1
               Dim c As New HtmlTableCell()
                c.Controls.Add(new LiteralControl("第" & (j).ToString() & "行" & _
                               "，第" & (i+1).ToString() & "列"))
               r.Cells.Add(c)
            Next i
            Table1.Rows.Add(r)
         Next j
	
	End Sub

      Sub Submit3(sender As Object, e As EventArgs)
	Dim mod1 as Integer =0
	Dim row as Integer =0
 	Dim numrows As Integer = Convert.ToInt32(Select1.Value)
        Dim numcells As Integer = Convert.ToInt32(Select2.Value)

	Message.InnerHtml=""
	if numrows mod 6 <> 0 
		 mod1=1
	end if
	page=numrows \ 6+mod1
	if k > 0 
	k -=1
	end if 
	Dim j as Integer =0
	 For j = k*6+1 To min((k+1)*6,numrows)
            Dim r As New HtmlTableRow()

            If row Mod 2 = 1 Then
               r.BgColor = "Gainsboro"
            End If
            row += 1
            Dim i As Integer
            For i = 0 To numcells - 1
               Dim c As New HtmlTableCell()
                c.Controls.Add(new LiteralControl("第" & (j).ToString() & "行" & _
                               "，第" & (i+1).ToString() & "列"))
               r.Cells.Add(c)
            Next i
            Table1.Rows.Add(r)
         Next j
	
	End Sub

      Sub change1(sender As Object, e As EventArgs)
	if StateSelect.Value = ""
     	    
   	    Message.InnerHtml="请您首先输入行列值，然后生成表格"
	    return
	 end if 
	  Dim mod1 as Integer =0
	Dim row as Integer =0
 	 Dim numrows As Integer = Convert.ToInt32(Select1.Value)
         Dim numcells As Integer = Convert.ToInt32(Select2.Value)
	 if numrows mod 6 <> 0 
		 mod1=1
	  end if
	 page=numrows \ 6+mod1
	k=Convert.ToInt32(StateSelect.Value)-1
	Dim j as Integer =0
	 For j = k*6+1 To min((k+1)*6,numrows)
            Dim r As New HtmlTableRow()

            If row Mod 2 = 1 Then
               r.BgColor = "Gainsboro"
            End If
            row += 1
            Dim i As Integer
            For i = 0 To numcells - 1
               Dim c As New HtmlTableCell()
                c.Controls.Add(new LiteralControl("第" & (j).ToString() & "行" & _
                               "，第" & (i+1).ToString() & "列"))
               r.Cells.Add(c)
            Next i
            Table1.Rows.Add(r)
         Next j
	End Sub

	Function min(x as integer,y as integer) as integer
	if x>y 
	return y
	else
	return x
	end if
	End Function
    </script>

</head>
	<body>
		<h3>
			<font face="Verdana">第十三例 HtmlTable控件的使用</font>
		</h3>
		<form runat="server">
			<font face="Verdana" size="-1">
				<p>
					<table id="Table1" CellPadding="5" CellSpacing="0" Border="1" BorderColor="black" runat="server" />
					<input id="Submit31" type="button" value="上一页" runat="server" Onserverclick="Submit3">
					<input id="Submit21" type="button" value="下一页" runat="server" Onserverclick="Submit2">
					<span id="Message1" runat="server" /><select id="StateSelect" runat="server" />页
					<input type="submit" value="提交" runat="server" Onserverclick="Change1">
				<p>
					请您输入表格行数: <input type="text" id="Select1" runat="server">
					<br>
					请您输入表格列数: <input type="text" id="Select2" runat="server">
					<BR>
					<input type="submit" value="生成表格" Onserverclick="Submit1" runat="server">
			</font>
		</form>
		<span id="Message" runat="server" />
	</body>
</html>
