Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically generated textboxes?

Status
Not open for further replies.

JaneB19

Technical User
Jun 27, 2002
110
GB
Hi,

I'm not sure if I should be posting this here or in the ASP.net forum.

What I would like to do is dynamically generate a number textboxes depending on the number selected from a radioButton list. i.e. if the radio button for '4' was selected then 4 textboxes would be generated.

I have a FOR loop, but I don't really know how to do the textboxes, do I declare them as textboxes or objects?

The FOR loop is as follows:

Dim i As Integer
Dim LettersFound As TextBox
Dim dsLetFound As DataSet

For i = 0 To "No_Letters"
LetFoundTable.LettersFound()
Response.Write(LettersFound)
Next


I think that I might have gotten a little confused, but I'm not sure about how to return them.

"No_Letters" is the name of the RadioButtonList.
LetFoundTable is the table that the textbox is in.

Hope that I've been making sense, any questions please ask!

Thanks in advance, any help is greatly appreciated

Jane :)
 
If you're going to add the textboxes to a table, then you may have to dynamically add a table row to that table, then add the textbox control in a cell of that row.

You can use the TextBox object as the type of object (doesn't need to be generic or anything, or cast later).

D'Arcy
 
Hi D'Arcy
Thanks for your reply.

I am really only using the table as layout, and generating the textboxes in the one cell as I need to use them later in a query.

I'm creating an online crossword solver and this is part of an advanced search. The radioButtonList is set as AUTOPOSTBACK = TRUE so that once the user can selects the number of letters in the solution from the radioButtonList. The number of textboxes generated depends on what's selected, and the user can enter any letters found into the text boxes (each textbox will contain only one character).

I've changed my coding a bit, but I'm still don't know how to 'write' the textboxes to the form

Dim i As Integer
Dim LettersFound As TextBox

For i = 0 To "No_Letters"
LetFoundTable(LettersFound.Text)
i = i +1
Next

I've got a nice blue squiggle under LetFoundTable(LettersFound.Text)

Thanks again for your help (in advance too)
Jane :)
 
you could use an array like this

Public txtEntry() As System.Windows.Forms.TextBox
then in your subroutine

dim intNum as integer = txtHowMany.text 'how many they chose
dim intT as integer
dim intWhere as integer = 30
ReDim Preserve txtEntry(intNum)

For intT = 0 To intNum
txtEntry(intT) = New TextBox()
txtEntry(intT).Location = New Point(1, intWhere)
txtEntry(intT)Size = New Size(41, 20)
txtEntry(intT).Text = ""
.Controls.Add(txtEntry(intT))
intWhere =+ 30
Next
 
Thanks for your reply Michelle!

Sorry, but my VB.net isn't so great. I was wonding if you could possibly explain what's going on in the code? I'm not too sure why you've got Point and Size in the array?

I didn't think that replicating one textbox to X number of them would be so complicated! %-)

Thanks again
Jane :)
 
point is where the textbox is going to be on the form and size is how big you want the textbox to be.
Michelle
 
Jane is asking for adding textboxes on WebForms. Michelle is providing a WinForms answer.

I would ask this in the ASP.Net forum.
 
Thanks for all of your help.

I'll try in the ASP.net as suggested

Jane :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top