Better Way???

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
 
S

Scott M.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top