[RESOLVED]how to bind selected text in dropdown to listbox in mvc2

my require is selected text in drop down list have bind to the list box using json result set..

in controller :

  public JsonResult Bindcolumnname(string res)
        {
            ds = ObjAuth.ColList(res);
            obj.dt = ds.Tables[0];

            return Json(obj, JsonRequestBehavior.AllowGet);
        }

this data how can i will bind to the listbox..

please see http://msprogrammer.serviciipeweb.ro/2011/12/05/jquery-ajax-request-and-mvcdetailed/

Hi divya,

For this requirement, you need to iterate JSON data and append the option item to the ListBox (select element).

For example:

$.get('URL', function(data) {
 var innerOptions="";
  $.each(data, function(i, item) {
   innerOptions+="<option value="+data[i].[property name])+">"+data[i].[property name]+"</option>";
  });‚Äč
 $("#your listbox id").append(innerOptions);
});

These threads that can help you:

# Jquery adding and removing items from listbox

http://stackoverflow.com/questions/15549027/jquery-adding-and-removing-items-from-listbox

# jquery loop on Json data using $.each

http://stackoverflow.com/questions/2342371/jquery-loop-on-json-data-using-each

Best Regards

Starain

Leave a Reply