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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generate controls dynamically 1

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
hi all,

i wanted to know if there is a way to generate controls (like a textbox) into a for loop. This means that depending on the result of a query, i will get a number X , and will have to generate X textbox.
I'm affraid not but maybe am i wrong ... Hope so.

ie :

For i=0 to myDataset.Tables("Languages").Columns.Count then
'create the textbox, and set myTextbox.name = ds.Tables("Languages").Columns(i).ColumnName
Next



Best regards,
Elise, XML girl X-)
 
Create a placeholder. Name it 'plcControls'. Place it on the page where you want the textboxes to be, and this is where you'll add them:
Code:
dim txtBox as textbox
For i=0 to myDataset.Tables("Languages").Columns.Count then
    txtBox = new textbox
    txtBox.id = ds.Tables("Languages").Columns(i).ColumnName
    plcControls.Controls.Add(txtBox)
Next
:)
paul
penny1.gif
penny1.gif
 
thanks, it works.
I will use this solution if i find a way to customize the display of the place holder.

thanks Best regards,
Elise, XML girl X-)
 
Customize in what way?

What are you looking for?
penny1.gif
penny1.gif
 
for exemple to have a carriage return on the webpage for each control ? Best regards,
Elise, XML girl X-)
 
I'm not sure if this will help, but you could always dynamically build a table to put the controls in. This way each text box could be in its own table row. I have some sample code if would like to see it and you think it might help.

Ken
 
well i'd like to see the code yes thanks :)
elise.d@laposte.net
Best regards,
Elise, XML girl X-)
 
Elise,

Here is some sample code that I hope will help:

I added a asp table to a form:

<asp:Table id=&quot;Table1&quot; runat=&quot;server&quot;></asp:Table>

Then in the code behin I added the following to the page load event to get three text boxes to show:

Dim ctr As Integer
For ctr = 1 To 3
'Generate table row &quot;<tr>
Dim tmpTableRow As New TableRow()

'Generate table data &quot;<td>&quot;
Dim tmpTableCell As New TableCell()

'Genereate Text Box
Dim tmpTxtBox As New TextBox()
tmpTxtBox.ID = &quot;txtBox&quot; & ctr

'Add text box to table cell
tmpTableCell.Controls.Add(tmpTxtBox)

'Add &quot;<td>&quot; to &quot;<tr>&quot;
tmpTableRow.Controls.Add(tmpTableCell)

'Add &quot;<tr>&quot; to table
Table1.Controls.Add(tmpTableRow)
Next

I hope this helps out. If you have any questions please let me know.

Ken

 
thanks it works :) Best regards,
Elise, XML girl X-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top