mahesh
mahesh

Reputation: 3217

How to construct a database driven Jquery dropdown menu in asp.net

I am trying to build a fancy jquery dropdown menu ,while making the menu items dynamic by bringing the values of menu items from database. I am using asp.net and sql server 2005 as my database,Is their any simple article to work this?

Upvotes: 1

Views: 2450

Answers (2)

tushar
tushar

Reputation: 23

$.ajax({
     url: yoururl,
     data: { yourfunctiondatavariable},
     cache: false,
     type: "POST",
     success: function (data) {
     var markup = "<option value='0'>----Select----</option>";
     for (var x = 0; x < data.length; x++) 
     {
     debugger
     markup += "<option value=" + data[x].Value + ">" + data[x].Text + "</option>";
      }        
      $("#dropdownname").html(markup).show();
    },
   error: function (reponse) {
   alert("error : " + reponse);
   }
});

Upvotes: 0

Fourth
Fourth

Reputation: 9351

http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Create a page method that your jquery ajax can call and get results from. Populate the dropdown on click, just remember to do something to let the user know that the values are coming since the database might not respond instantly.

Upvotes: 3

Related Questions