Adding Tables dynamically??

  • Thread starter Thread starter grawsha2000
  • Start date Start date
G

grawsha2000

Hello,

How can I add a table to asp.net page dynamically with Code Behind
style.

I still can't find a way of doing it. This really causes me a big
problem when I deal with records from database as I need to construct
the table dynamically.


MTIA,
Grawsha
 
(e-mail address removed) wrote in @l41g2000cwc.googlegroups.com:
Hello,

How can I add a table to asp.net page dynamically with Code Behind
style.

I still can't find a way of doing it. This really causes me a big
problem when I deal with records from database as I need to construct
the table dynamically.


1. Take a look at a datagrid... it's great for grid like data. No point
in rewriting a grid...

2. If you want to use a table, place a table onto the webpage (or a
placeholder).

Then do the following:

dim cell as tablecell
dim row as tablerow


For Loop Here
cell = new tablecell
row = new tablecell
row.cells.add(cell)
table.rows.add(row)
Next


That's how you add a row.
 
There are a few options which you can take:

1. Look into using the Repeater or DataGrid controls to display your
records

2. You can add an <asp:Label...> control to your form, then in the
code-behind, generate your table structure through a
"<table><tr><td>...</td></tr></table>" string and assign that string to the
Label1.Text property.

3. Dynamically create an ASP.NET table and add it to the Control collection
of a Placeholder object. (code shown below)
- In the ASPX form, create an <asp:Placeholder object (name "plc") where
you would like the table to go
- In the code-behind, dynamically generate the table and add the table
to PlaceHolder.Controls
Dim tbl As New System.Web.UI.WebControls.Table

Dim row As System.Web.UI.WebControls.TableRow

Dim cell As System.Web.UI.WebControls.TableCell

row = New System.Web.UI.WebControls.TableRow

tbl.Rows.Add(row)

cell = New System.Web.UI.WebControls.TableCell

cell.Text = "Test"

row.Cells.Add(cell)

plc.Controls.Add(tbl)


HTH,
Jody
 

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

Back
Top