2016-10-15 6 views
-2

私は同じアイテムで2つのドロップダウンを持っています。 1つ目のドロップダウンで1つのアイテムが選択されている場合は、次のドロップダウンに表示されません。asp.netのドロップダウン検証

+0

あなたが何をしたか、あなたのコードを共有する場合、それは良くなる最初のドロップダウン – Denzil

+0

のOnChangeイベントで2番目のドロップダウンにデータを再割り当てすることによって選択された値を削除します。**それはいけません次のドロップダウンリストに表示されます**、最初のドロップダウンリストがいくつかの項目で選択された場合、その項目は2番目のドロップダウンリストに表示されませんか? –

+0

これはカスケード 'DropDownList'を使ったようです。この機能がなければ、動作しません。コードを共有し、カスケードを削除しようとします。 –

答えて

0

Working Demo

$(function() { 

    var lastRemovedIndex = -1; 
    var lastRemovedOptionHtml = null; 


    $('#ddl1').change(function() { 

    if (lastRemovedIndex == -1) 
    { 
    //both must have equal(and non-zero) number of children 
    if ($(this).children().length < 1 || $(this).children().length != $('#ddl2').children().length) 
     return;   
    else 
    { 
     //if a has n children then b must have n-1 as 1 child was removed from b 
     if ($(this).children().length - 1 != $('#ddl2').children().length) 
      return; 

    //Little complex. It says add the last removed option at its last position 
     if (lastRemovedIndex != $('#ddl2').children().length) 
      $('#ddl2').children().eq(lastRemovedIndex).before($(lastRemovedOptionHtml)); 
     else 
      $('#ddl2').append(lastRemovedOptionHtml); 
    } 
    var objectToBeRemoved = $('#ddl2').children().eq(this.selectedIndex); 
    lastRemovedIndex = objectToBeRemoved.index(); 
    lastRemovedOptionHtml = objectToBeRemoved[0].outerHTML; 
    objectToBeRemoved.remove(); 
    }); 


});