how to dynamically create web controls without placeholder

D

Dica

i need to dynamically add a web control to a page without using placeHolder.
i'm looping through all the files in a folder and creating a table row as
string for each file. the contol is to be nested in that row as follows:

sTblRow = "<tr><td>" + sFrom + "</td><td><asp:DropDownList id=\"lstAction_"
+ filename + "\" runat=\"server\<asp:ListItem
Value=\"deliver\">Deliver</asp:ListItem><asp:ListItem
Value=\"whitelist\">Whitelist</asp:ListItem><asp:ListItem
Value=\"delete\">Delete</asp:ListItem><asp:ListItem
Value=\"blacklist\">Blacklist</asp:ListItem></asp:DropDownList></td></tr>";

the sTblRow string is then written to a literal control on the aspx page.

this doesn't work though. the control isn't recognized as a web control and
just displays as text. i can't really use a placeHolder as the table rows
themselves are dynamically created. any ideas how to pull this off?



tks
 
D

David Williams

Well, assuming that this is copied from the real code and not added
manually, this code would not work as is in any case. In the
DropDownList control the runat attribute is missing a quote. That could
cause the control to not be recognized.
 
D

Dica

Well, assuming that this is copied from the real code and not added manually, this code would not work as is in any case. In the DropDownList control the runat attribute is missing a quote. That could cause the control to not be recognized.


yeah, that's a typo here only. there is an end quote in my code.
 
P

Patrice

You could have a server side table control. This way you'll be able to use
its programming model and add rows objects to this table. In a cell you'll
be able to add a dropdowncontrol as a server side control etc...

Here the problem is likely that you render some text to the browser (i.e.
you'll see asp:DropDownlist client side).

You could also use a Repeater or perhaps a DataList/GridView etc...
 
D

Dica

Patrice said:
You could have a server side table control. This way you'll be able to use
its programming model and add rows objects to this table. In a cell you'll
be able to add a dropdowncontrol as a server side control etc...

good suggestions. tks.
 

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

Top