您好 如何将项添加到动态创建的select(html)Control ..
感谢
答案 0 :(得分:8)
要在服务器端添加项目,请使用HtmlSelect.Items属性。例如,
var select = control as HtmlSelect; // may not be needed
var items = select.Items;
// Add items to the collection.
items.Add(new ListItem("apples", "1"));
items.Add(new ListItem("bananas", "2"));
items.Add(new ListItem("cherries", "3"));
答案 1 :(得分:1)
您可以使用javascript来执行此操作,例如
<script type="text/javascript">
function AddItem(Text,Value)
{
// Create an Option object
var opt = document.createElement("option");
// Add an Option object to Drop Down/List Box
document.getElementById("myDropDownList").options.add(opt);
// Assign text and value to Option object
opt.text = Text;
opt.value = Value;
}<script />