Access TextBox.Text inside a Dynamically Created Table (Code behind = vb)

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

Guest

I'm using a table (dynamically generated at runtime) for formatting wherein I have text in the first column, and textboxes in the second column. For example, (1,1) might have the string "Last Name" and (1,2) has a textbox where the user can type the last name; (2,1) "First Name", and (2,2) a textbox, and so forth. The code to it is:

dim table_test As System.Web.UI.WebControls.Table

For rowCount = 0 To 3
Dim column1 As New TableCell()
Dim column2 As New TableCell()
Dim row As New TableRow()

column1.Controls.Add(New LiteralControl("something"))
column2.Controls.Add(New TextBox())

row.Cells.Add(column1)
row.Cells.Add(column2)

table_test.Rows.Add(row)
Next

Once the table is generated, and presented, how can I fetch the contents of the textboxes in the second column? The following does not work because I don't want the text within the cell, I want the text within the textbox within the cell (I'm assuming the rows and cells are zero origined, I might be wrong):

dim s as string
s = table_test.rows(0).cells(1).text

Any suggestions will be greatly appreciated!
 
Hi,

Usually when I want to do something like that I use only one text box. When
the user click on an "editable" field I resize the text box and I move it
above the cell. I initialize the control with the text of the cell. When the
user validate his changes by clicking an other cell or typing Enter or Tab.
I replace the content of the cell by the text typed in the text box.

It's much more easy with dot Net because your table use already an object
structure. You'll don't have to save data because it will be directely
stored in properties of cells, rows and columns.

I hope this will help you, and excuse my enlish...

Regards

Laurent Jordi
http://www.eztree-msdn.com


NewBee said:
I'm using a table (dynamically generated at runtime) for formatting
wherein I have text in the first column, and textboxes in the second column.
For example, (1,1) might have the string "Last Name" and (1,2) has a textbox
where the user can type the last name; (2,1) "First Name", and (2,2) a
textbox, and so forth. The code to it is:
dim table_test As System.Web.UI.WebControls.Table

For rowCount = 0 To 3
Dim column1 As New TableCell()
Dim column2 As New TableCell()
Dim row As New TableRow()

column1.Controls.Add(New LiteralControl("something"))
column2.Controls.Add(New TextBox())

row.Cells.Add(column1)
row.Cells.Add(column2)

table_test.Rows.Add(row)
Next

Once the table is generated, and presented, how can I fetch the contents
of the textboxes in the second column? The following does not work because I
don't want the text within the cell, I want the text within the textbox
within the cell (I'm assuming the rows and cells are zero origined, I might
be wrong):
 
Back
Top