1
  my Jquery code
 ("#<%=cboBranch.ClientID%>").append($("<option></option>").attr("value",valueData1).text(Data1))

 my asp code
 <asp:DropDownList ID="cboBranch" runat="server" class="medium" >

How can I do it? Its not working

3
  • Your JQuery code looks fine; the problem must be something else you're not showing here (eg, script executing before HTML is loaded). Can you provide a short, self-contained, compilable example? sscce.org Commented Sep 20, 2012 at 5:04
  • Do you want to fill dropdown with JSON data? Commented Sep 20, 2012 at 5:06
  • Yes, I done already the JSON and I dont know how to populate it in dropdown. This is a usercontrol. Can you show me how? Commented Sep 20, 2012 at 5:12

2 Answers 2

3

Are you looping the data?

// clear dropdown
    $("#<%=cboBranch.ClientID%>").html("");
    for (var i = 0; i < data.length; i++) {
        var item = data[i];
        $("#<%=cboBranch.ClientID%>").append(
              $("<option></option>").val(item.Id).html(item.Name);
        );
    });

Read this

Sign up to request clarification or add additional context in comments.

1 Comment

It didnt work, I think the problem is this is not a page this is a usercontrol in .NET.
1

supposing result is your JSON data then do something like this

$.each(result, function() {
    options.append($("<option />").val(this.Value).text(this.Name));

Comments

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.