dipti prasad

dipti prasad

  • NA
  • 76
  • 39.2k

how to fill dropdown from database in jqgrid in mvc??

Dec 24 2014 7:57 AM
Hello Friends,
 
Please help  me in jqgrid.
how to add dynamic dropdownlist  in jqgrid in add dilogue box ??
my code is working like in controller my data is come from database but not display in dropdownlist.
 
My  View ....................
 
{
name: "Per", index: 'Code', align: "right", sortable: true, editable: true, edittype: 'select', editrules: { required: true }, formoptions: { rowpos: 5, colpos: 2 },
editoptions: {
dataUrl: '/Sales/Category'
, buildSelect: function (response) {
var data = typeof response === "string" ? $.parseJSON(response.responseText) : response;
var s = "<select>";
s += '<option value="0"></option>';
$.each(data, function () {
s += '<option value="' + data.Code + '">' + data.Name + '</option>';
})
return s + '</select>';
}
}, editrules: { required: true }


},// multiple: true,
 ....................................................................................................................................................
My Controller code 
 
public JsonResult Category()
{
TFAT_WEBERPEntities ctx = new TFAT_WEBERPEntities();
List<string> listSelectListItems = new List<string>();
var company = from name in ctx.TfatComps select name.Name;
listSelectListItems.AddRange(company.Distinct());
ViewData["Per"] = new SelectList(listSelectListItems);
return Json(listSelectListItems, JsonRequestBehavior.AllowGet);
// return View();
 
 
 
 
 
 
 
 
 
 

Answers (3)