2011-04-12 69 views

回答

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 /> 
7

要在服務器端添加項目,請使用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")); 
相關問題