直截了当,我使用ASP.NET 3.5(C#),我的下拉列表中有3个项目。 所以,我想在ddl验证中创建事件。 例如,
if (ddl.selectedvalue ==1) { One textbox added to my form }
else if (ddl.selectedvalue==2) { Two textbox added to my form}
提前谢谢你:)
答案 0 :(得分:1)
在表单中打开占位符。
<asp:PlaceHolder id="placeHolderID" runat="server" />
现在你的代码在.cs文件中
您可以编写如下代码,
int value = Convert.ToInt32(ddl.selectedvalue.ToString());
for(int i = 1; i < value + 1 ; i ++)
{
TextBox txt = new TextBox();
txt.ID = "newTxt" + i;
placeHolderID.Controls.Add(txt);
}
答案 1 :(得分:0)
在表单中打开占位符。
<asp:PlaceHolder id="placeHolderID" runat="server" />
现在你的代码在.cs文件中
if (ddl.selectedvalue ==1)
{
TextBox txt1 = new TextBox();
txt1.ID = "newTxt1";
placeHolderID.Controls.Add(txt1);
}
类似于下一个条件。