page_load时候,dropdownlist里面已经绑定了
                    ddl.DataSource = InfoList;   //IList<InfoList>
                    ddl.DataValueField = "ID";
                    ddl.DataTextField = "Name";
                    ddlSalesagents2.DataBind();那么,如果页面触发js方法,要根据某个Id,让那条记录被selected,怎么写?

解决方案 »

  1.   

    干嘛不在 Server 端处理好直接发过去呢?!
      

  2.   

    id是   页面进行某些操作后,ajax得到的  。 所以不能Server 端处理好
      

  3.   


    document.getElementById('<%=ddl.ClientID%>').value = yourId;
      

  4.   

    呵呵,L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
      <select id="selPerson">
    <option value="" selected>请选择</option>
    <option value="3">张三</option>
    <option value="4">李四</option>
    <option value="5">王五</option>
      </select>
      <script type="text/javascript">
      <!--
    function SelectPersonById(pId) {
    var sel = document.getElementById("selPerson");
    for (var i=0, len=sel.options.length; i < len; i++) {
    if (sel.options[i].value==pId) {
    sel.options[i].selected = true;
    break;
    }
    }
    }var personId = 4;
    SelectPersonById(personId);
      //-->
      </script>
     </body>
    </html>