简体   繁体   中英

Asp.net Dynamic controls dropdownlist and textbox prob

我已经在asp.net中动态创建了2个下拉列表和2个文本框。我在运行时禁用了文本框。我希望当我从下拉文本框中选择项目时应启用如何执行此任务的方法,请帮助我:(

On SelectedIndexChanged on the dropDownList call a function that sets the textbox enabled = true. To access controls that have been dynamically added you can use FindControl as per C#, FindControl

I think something like this should help you:

In your page's OnInit event:

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);

Inside the instantiated event handler:

void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    yourTextbox.Enabled = true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM