Adding Textbox to table at run time

K

Ken Dippold

Hello, I am trying to create textboxes in a table that has a certain amount
of cells decided at run time. That is decided by the desc_flag.
So if I have 7 cells the first 6 cells are empty and only the 7th cell gets
the text box.

there will be 2 rows in this table the first row displays data, the second
will be text boxes for entry. Any Help will be greatly appriciated

Thanks
Ken


Dim numrows As Integer = 2

Dim numcells As Integer = desc_flag

Dim j As Integer

Dim text As New TextBox

For j = 0 To numrows - 1

If j > 0 Then GoTo 30

Dim r As New TableRow

Dim i As Integer

Dim w As Integer = 5

For i = 0 To numcells - 1

Dim c As New TableCell

c.Controls.Add(text)

r.Cells.Add(c)

w = w + 1

Next i

Table1.Rows.Add(r)

Next j
 
E

entdevguy

I would recomend name the labels lblLabel1, lblLabel2, lblLabel3,
etc.. then using Table1.FindControl("lblLabel" + index) to set the
visibility and retrieve the Text. This is a lot easier then building
the table dynamicaly. Building the table dynamicaly will require you
to build it exactly the same from post-to-post to maintain and load
viewstate properly. It gets more complicated if this is a UserControl
becuase you must implement an event model to call back parent controls
after the table has been rebuilt and viewstate loaded.

EntDevGuy
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top