1

I have ASP.Net DropDownList bind using c#. I want to change selected value of DropDownList on Button Click Event using JQuery.

<asp:DropDownList ID="ddlSubject" runat="server" >
</asp:DropDownList>


           I have tried this but did not work:          
      $( '#< %=ddlSubject.ClientID %> option:selected' ).val( "5" );

2 Answers 2

2

If you haven't enclosed your dropdown in any grid or other container, use this:

$("#ddlSubject").val("5");

If not, use this:

$("#<%=ddlSubject.ClientID%>").val("5");
Sign up to request clarification or add additional context in comments.

Comments

0

You can set value using this

$("#<%=ddlSubject.ClientID%>").val("5");

4 Comments

Try this ` $( '#< %=ddlSubject.ClientID %> option[value="5"]').attr('selected','selected').`
Badluck. Not working. I have bound dropdowlist using C# datasource. Is it because of that its not working?
You can set selected value from c# also.like this ddlSubject.Items.FindByValue(5).Selected = true;
Yes I can. But I want to do it using jQuery/javascript only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.