Better Way???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am new to asp.net. Is there a better way to do the following code?

Dim Cell1 As New System.Web.UI.WebControls.TableCell
Dim Cell2 As New System.Web.UI.WebControls.TableCell
Dim Cell3 As New System.Web.UI.WebControls.TableCell
Dim Cell4 As New System.Web.UI.WebControls.TableCell

Cell1.Text = "cell1"
Cell2.Text = "cell2"
Cell3.Text = "cell3"
Cell4.Text = "cell4"

Table1.Rows.Add(New System.Web.UI.WebControls.TableRow)

Table1.Rows(Table1.Rows.Count - 1).Cells.Add(Cell1)
Table1.Rows(Table1.Rows.Count - 1).Cells.Add(Cell2)
Table1.Rows(Table1.Rows.Count - 1).Cells.Add(Cell3)
Table1.Rows(Table1.Rows.Count - 1).Cells.Add(Cell4)

Cell1.Dispose()
Cell2.Dispose()
Cell3.Dispose()
Cell4.Dispose()

I have a recordset that I am trying to add to display on the page. I
already have a table with some data in it. I am trying to append the
new data to. If there is a better way of doing this I would greatly
appreciate it.

Thanks again
 
You should consider moving away from the "building tables manually to
display data" paradigm of classic ASP and move towards the dynamic features
of Web Form controls and ADO.NET.

I wouldn't do any of what you have here (and, by the way, there is no need
for you to call dispose on a cell object - - only objects that use unmanaged
resources would need a dispose call).

You can populate a DataSet (no more recordsets) with your data and simply
bind an ASP.NET DataGrid control to that DataSet. No manual table creation
necessary.

-Scott
 
Back
Top