我 在asp.net .i中动态创建了2个下拉列表和2个文本框。在运行时禁用文本框。我希望当我从下拉文本框中选择项目时应启用如何执行此任务请帮助我:(< / p>
答案 0 :(得分:0)
在dropDownList上的SelectedIndexChanged上调用一个设置textbox enabled = true的函数。要访问已动态添加的控件,您可以按C#, FindControl
使用FindControl答案 1 :(得分:0)
我认为这样的事情可以帮到你:
在您网页的OnInit事件中:
DropDownList ddl = new DropDownList();
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
placeholder.Controls.Add(ddl); //assuming this is what you use to dynamically show the dropdown list
TextBox yourTextbox = new TextBox(); //declare the variable outside to be able to be accessed by other methods, but it must be instantiated here. declaration here is for illustration purposes only
yourTextBox.Enabled = false;
placeholder.Controls.Add(yourTextBox);
在实例化的事件处理程序中:
void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
yourTextbox.Enabled = true;
}