http://bytes.com/forum/thread312759.html
Hi, I'm working on a project in witch I have to list data(products that can be selected with a certain quantity) from anXML document, with key words entered by the user. A Table isdynamically created with text, and in each row, there 's a textBox (with an incremental ID number) in witch the user can enter a number of products. When the user clicks on the "Submit"button, I must know witch row he has selected, AND WITCH NUMBERHE HAS ENTERED in the The TextBox area.
The problem is that the Table is created dynamically (the userhas clicked on a "search" button to create the Table) so I can't use the AutoPostBack of each TextBox, or I lose the entireTable. I thought about using ViewState, but to store data I must know when the Text of the TextBox changed. I tried to do this with a Add Handler, but the TextChanged Method is never called!!
I don't know how to solve this problem. Help me !!!
Here is a part of my code (where numResult is the number of rows):
Protected TableResult As Table
Dim numResult As Integer
'(My TextChanged Function to store info)
Public Sub TB_Changed(ByVal sender As Object, ByVal e AsEventArgs)
Dim i As Integer = 0
While (i < numResult)
ViewState(Convert.ToString(i)) = sender.Text
i = i + 1
End While
End Sub
'(A part of the function that fill the Table)
Public Sub ResultsView(ByVal PRef As String, ByVal PDes AsString)
Dim compteur As Integer = 0
Dim r As New TableRow
Dim c1 As New TableCell
c1.Text = "Qt?"
r.Cells.Add(c1)
TableResult.Rows.Add(r)
While (compteur < numResult)
Dim ro As New TableRow
Dim ce1 As New TableCell
Dim txtB As New System.Web.UI.WebControls.TextBox
txtB.ID = Convert.ToString(compteur)
AddHandler txtB.TextChanged, AddressOf TB_Changed
ce1.Controls.Add(txtB)
ro.Cells.Add(ce1)
compteur = compteur + 1
End While
End Sub
Thank u for responding
(I hope u'll understand, my English is not really good...)
--------------------------------
From: Forconi Boris
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>I/JHNHTdekGGZdBcrf9RWA==</Id>
Hi,
I'm doing something very similar right now. Here's how you can do it:
Dynamically add as many controls as you need to in your table (or panel),
and assign them an ID that is easily referenced.
When the user clicks on the submit button, you can find the value of each
textbox this way (If you know the ID's of the textboxes)
dim c as control
dim w as string
c = table1.findcontrol('TheID')
w = ctype(c,textbox).text
Hope this helps,
Steve