2017-02-11 36 views
0

ASP.NET WebForms - 當在我的父列表框中創建新選擇時,它僅附加子列表框,而不是先清除它,然後添加附加列表。將新選擇添加到父項時,子列表框不會清空

的.aspx

function GetContacts() { 

     var LstRight; 
     var locationIDs = ''; 



     var LstRight = document.getElementById("<%=lstSelectedFranchises.ClientID %>"); 
     for (i = 0; i < LstRight.length; i++) { 
      locationIDs = locationIDs + LstRight.options[i].value + ','; 
     } 

     $.ajax({ 
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      url: '<%= ResolveUrl("~/CallReportDetail.aspx/getContacts") %>', 
      data: "{'jData':" + JSON.stringify(locationIDs) + "}", 
      dataType: "json", 
      success: function (result) { 

       $('#lstAllContacts').empty(); 
       $('#lstSelectedContacts').empty(); 

       //alert(JSON.stringify(result.d)); 

       for (i = 0; i < result.d.length; i++) 
        $('#<%=lstAllContacts.ClientID %>').append($('<option>').text(result.d[i].Contact).val(result.d[i].ID)); 

      }, 
      error: function (xhr, ajaxOptions, thrownError) { 
       alert("There was a problem getting the contact list for your selected franchise(s): " + thrownError); 

      } 
     }); 
    } 

查看

 <strong>Franchise(s)</strong><br /> 
    <table style="border:none"> 
     <tr> 
      <td> 
       <asp:TextBox ID="txtSearchFranchises" runat="server" onkeyup="return SearchFranchiseList();"></asp:TextBox><br /> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <asp:ListBox ID="lstAllFranchises" runat="server" SelectionMode="Multiple" Rows="10" Width="300px"></asp:ListBox> 
      </td> 
      <td> 
       <asp:LinkButton ID="btnAddFranchises" runat="server" Text="Add >>" Style="text-align:center; width:100%" OnClientClick="return MoveFranchises('R', 0);" CssClass="btn btn-primary btn-sm"/><br /> 
       <asp:LinkButton ID="btnRemoveFranchises" runat="server" Text="<< Remove" Style="text-align:center; width:100%" OnClientClick="return MoveFranchises('L', 0);" CssClass="btn btn-primary btn-sm"/><br /> 
       <asp:LinkButton ID="btnAddFranchisesAll" runat="server" Text="Add All >>" Style="text-align:center; width:100%" OnClientClick="return MoveFranchises('R', 1);" CssClass="btn btn-primary btn-sm"/><br /> 
       <asp:LinkButton ID="btnRemoveFranchisesAll" runat="server" Text="<< Remove All" Style="text-align:center; width:100%" OnClientClick="return MoveFranchises('L', 1);" CssClass="btn btn-primary btn-sm"/> 
      </td> 
      <td> 
       <asp:ListBox ID="lstSelectedFranchises" runat="server" SelectionMode="Multiple" Rows="10" Width="300px"></asp:ListBox> 
      </td> 
     </tr> 
    </table><br /><br /> 


    <strong>Contact(s)</strong><br /> 
    <table style="border:none"> 
     <tr> 
      <td> 
       <asp:TextBox ID="txtSearchContacts" runat="server" onkeyup="return SearchContactList();"></asp:TextBox><br /> 
      </td> 
     </tr> 
     <tr> 
      <td> 
       <asp:ListBox ID="lstAllContacts" runat="server" SelectionMode="Multiple" Rows="15" Width="200px"></asp:ListBox> 
      </td> 
      <td> 
       <asp:LinkButton ID="btnAddContacts" runat="server" Text="Add >>" Style="text-align:center; width:100%" OnClientClick="return MoveContacts('R', 0);" CssClass="btn btn-primary btn-sm"/><br /> 
       <asp:LinkButton ID="btnRemoveContacts" runat="server" Text="<< Remove" Style="text-align:center; width:100%" OnClientClick="return MoveContacts('L', 0);" CssClass="btn btn-primary btn-sm"/> 
      </td> 
      <td> 
       <asp:ListBox ID="lstSelectedContacts" runat="server" SelectionMode="Multiple" Rows="15" Width="200px"></asp:ListBox> 
      </td> 
     </tr> 
    </table><br /><br /> 

任何人可以看到我要去哪裏錯了

回答

0

解決:改變了.empty()來。長度= 0

document.getElementById(「<%= lstAllContacts.ClientID%>」)。length = 0; document.getElementById(「<%= lstSelectedContacts.ClientID%>」)。length = 0;

相關問題