TextBoxes created dynamically : How to store data?

  • Thread starter Forconi Boris via .NET 247
  • Start date
F

Forconi Boris via .NET 247

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 atextBox (with an incremental ID number) in witch the user canenter 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'tuse the AutoPostBack of each TextBox, or I lose the entireTable. I thought about using ViewState, but to store data I mustknow when the Text of the TextBox changed. I tried to do thiswith a AddHandler, 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...)
 
S

Steve Caliendo

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




Hi, I'm working on a project in witch I have to list data (products that can
be selected with a certain quantity) from an XML document, with key words
entered by the user. A Table is dynamically 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 NUMBER HE HAS ENTERED in
the The TextBox area.

The problem is that the Table is created dynamically (the user has clicked
on a "search" button to create the Table) so I can't use the AutoPostBack of
each TextBox, or I lose the entire Table. 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 AddHandler, 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 As EventArgs)
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 As String)

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...)
 
T

Trevor Benedict R

Or you will have the values back in the controls if you recreate them in
the same order as before.

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top