2014-05-19 3 views
-3

jQuery를 사용하여 버튼을 클릭하여 드롭 다운 목록에서 3 번째 항목의 옵션을 선택하고 드롭 다운 목록 상자에서 '44'와 같이 옵션을 변경하려고합니다.jquery를 사용하여 버튼 클릭시 드롭 다운 옵션 선택

  <asp:DropDownList ID="DropDownList2" runat="server" 
       onselectedindexchanged="DropDownList2_SelectedIndexChanged"> 
       <asp:ListItem Selected="True">SELECT</asp:ListItem> 
       <asp:ListItem Value="1">23</asp:ListItem> 
       <asp:ListItem Value="2">32</asp:ListItem> 
       <asp:ListItem Value="3">44</asp:ListItem> 
       <asp:ListItem Value="4">61</asp:ListItem> 
      </asp:DropDownList> 

답변

0

당신은 사용할 수 있습니다 rednering 동안 ID가 변경 될 수 있으므로

$("#<%=DropDownList2.ClientID%>").val('3'); 
0

먼저 StaticClientIDMode을 설정합니다. 그런 다음

<asp:DropDownList ID="DropDownList2" runat="server" ClientIDMode="Static" 
       onselectedindexchanged="DropDownList2_SelectedIndexChanged"> 
       <asp:ListItem Selected="True">SELECT</asp:ListItem> 
       <asp:ListItem Value="1">23</asp:ListItem> 
       <asp:ListItem Value="2">32</asp:ListItem> 
       <asp:ListItem Value="3">44</asp:ListItem> 
       <asp:ListItem Value="4">61</asp:ListItem> 
      </asp:DropDownList> 

    <input type="button" id="MyButton"/> 

당신이 JQuery와 코드와 같이 수행 할 수 있습니다

$('#MyButton').click(function(){ 
    $('#DropDownList2').val("3"); 
}); 
0

다음 코드를 사용해보십시오 :

$('some_button_id').click(function() { 
    $('select[id*=DropDownList2]').val(3); //To select 44 
}); 

: 옵션을 선택

값을 사용하여 또는 ASP.NET 컨트롤의 ClientID를 사용하십시오.

$('some_button_id').click(function() { 
    $('select#<%=DropDownList2.ClientID%>').val(3); //To select 44 
}); 
0

이렇게하면

var dropDownList2ID = "#<%=DropDownList2.ClientID%>"; 
var buttonID = "#idOfButton"; 

//... 

$(buttonID).click(function() { 
    $(dropDownList2ID).val(3); 
}); 
도움이 될
관련 문제