我有以下代码:
HtmlGenericControl li = new HtmlGenericControl("li");
ULRouting.Controls.Add(li);
HtmlGenericControl anchor = new HtmlGenericControl("a");
li.Attributes.Add("myCustomIDAtribute", "11");
anchor.InnerText = "TabX";
li.Controls.Add(anchor);
我正在尝试找出当你动态创建li时如何向li控件添加一个下拉框,即:
<asp:DropDownList ID="cmbRoutingStage_1" runat="server" DataSourceID="sqlDBStages" DataTextField="stages" DataValueField="StageRefID"></asp:DropDownList>
答案 0 :(得分:0)
试试这个: -
DropDownList ddl = new DropDownList();
ddl.ID = "cmbRoutingStage_1";
ddl.DataSourceID = "sqlDBStages";
ddl.DataTextField = "stages";
ddl.DataValueField = "StageRefID";
li.Controls.Add(ddl);
作为旁注,您可以使用HtmlAnchor
类来生成锚标记: -
HtmlAnchor anchor = new HtmlAnchor();