2012-11-24 49 views
0

我需要使用从服务器端方法返回的对象列表填充DropDownList。由于这不应该导致页面刷新,我正在使用PageMethods。当我调试时,我可以看到正在调用onSuccess函数,但下拉列表没有被填充。对象列表也成功地从服务器端方法传递。我无法找出问题所在。使用PageMethod更新下拉列表

 function onsuccess(studList) 
    { 

      var ddl = document.getElementById('ddlStud'); 
      var count = ddl.options.length; 
      while (ddl.options.length > 0) 
      { 
       ddl.options.remove(0); 
      } 

      for (var i = 0; i < studList.length; i++) 
      { 

       var option = document.createElement('<option value="' + studList[i].id + '">'); 
       document.getElementById('ddlStud').options.add(option); 
       option.innerText = studList[i].StudName; 

      } 
     } 

回答

0

更新您的for循环:

 for (var i = 0; i < studList.length; i++) 
     { 
      var option = document.createElement('option'); 
      option.value= studList[i].id; 
      option.innerText = studList[i].StudName; 
      document.getElementById('ddlStud').options.add(option); 
     }