I’m trying to dynamically populate a dropdown when a user is trying to add a new record in a detail jqGrid. Here’s what I have so far. It’s pulling in the data fine but it just won’t set the value to the dropdown. Any help would be greatly appreciated.
beforeShowForm: function(formid) {
var sr = $("#list").jqGrid('selrow');
if (sr) {
// get data from master
var UserID = $("#list").getGridParam('selrow');
var roles = $.ajax({ type: "POST",
url: '<%= ResolveUrl("~/Admin/GetRoles/") %>' + UserID,
dataType: "json",
async: false,
success: function(data) {
}
}).responseText;
// set the field in detail with the value of mnaster
$("#UserID", formid).val(UserID);
// try and populate dropdown
$('#detail').setColProp('Description', { editoptions: { value: roles} });
} else {
// close the add dialog
alert("no row is selected");
}
}
In your first question I explained you how to use
dataUrlto generate the contain of the dropdown list dynamically. If you use form editing to modify the grid data you can usebeforeInitDatainstead ofbeforeShowFormto modify thedataUrlto'<%= ResolveUrl("~/Admin/GetRoles/") %>' + $("#list").jqGrid('selrow')before the form will be filled. In the way you can simplify your code, make theajaxrequest asynchronous and the question with setting the values to the dropdown control will be solved automatically.