how to dynamically create web controls without placeholder

  • Thread starter Thread starter Dica
  • Start date Start date
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
 
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.
 
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.
 
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...
 
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.
 
Back
Top