A couple of points to note:

1. When referencing an article on the web, it is always helpful to
provide a link to the said article. Also, it is useful to mention the
version of the framework you are programming against.

2. You have not mentioned *where* you query the NumberOfRows and
NumberOfColumns. Is it in the Button click handler("FR")? Is it in the
Page_Load event handler?

3. I tried to replicate your problem using the simple page below but
it works just fine for me. Note that I made certain changes such as
variable declarations, explicit casting (Tip: always keep Option
Explicit and Option Strict On when you're working in VB, if you want
to be a good programmer.) and single line instantiation.

---
<%@ Page Language="VB" Explicit="true" Strict="true" %>

<script runat="server" >

  Sub FR(ByVal sender As Object, ByVal e As EventArgs)
    Dim NumberOfRows, NumberOfColumns As Integer
    NumberOfRows = CInt(txtRows.Text)
    NumberOfColumns = CInt(txtCols.Text)
    Dim RR As New Random()
    T.Rows.Clear()
    For I As Integer = 0 To NumberOfRows - 1
      Dim r As New TableRow()
      For J As Integer = 0 To NumberOfColumns - 1
        Dim C As New TableCell()
        Dim v As Integer = RR.Next(0, 9)
        C.Text = CStr(v)
        r.Cells.Add(C)
      Next J
      T.Rows.Add(r)
    Next I

    lblNumRows.Text = "No. of Rows: " & CStr(T.Rows.Count)
    lblNumCols.Text = "No. of Cols: " & CStr(T.Rows(1).Cells.Count)
  End Sub

</script>

<html>
<head>
  <title>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <asp:Table ID="T" Font-Size="16" runat="server"
GridLines="Both">
        <asp:TableRow>
          <asp:TableCell>3</asp:TableCell><asp:TableCell>4</
asp:TableCell>
          <asp:TableCell>7</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
          <asp:TableCell>5</asp:TableCell><asp:TableCell>5</
asp:TableCell>
          <asp:TableCell>8</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
          <asp:TableCell>12</asp:TableCell><asp:TableCell>4</
asp:TableCell>
          <asp:TableCell>9</asp:TableCell>
        </asp:TableRow>
      </asp:Table><br />
      <label for="txtRows">Rows:&nbsp;</label>
      <asp:TextBox ID="txtRows" runat="server" /><br />
      <label for="txtCols">Cols:&nbsp;&nbsp;</label>
      <asp:TextBox ID="txtCols" runat="server" /><br />
      <asp:Button ID="btnCreate" runat="server" Text="Create"
OnClick="FR" /><br /><br />
      <asp:Label ID="lblNumRows" runat="server" Text="No. of Rows: 3" /
><br />
      <asp:Label ID="lblNumCols" runat="server" Text="No. of Cols: 3" /
><br />
    </div>
  </form>
</body>
</html>
---

Reply via email to