使用beforeShowForm事件填充jqGrid下拉列表

时间:2010-12-14 19:51:50

标签: javascript jqgrid

当用户尝试在详细信息jqGrid中添加新记录时,我正在尝试动态填充下拉列表。这是我到目前为止所拥有的。它正在提取数据,但它不会将值设置为下拉列表。任何帮助将不胜感激。

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");
       }

   }

1 个答案:

答案 0 :(得分:2)

first question我解释了如何使用dataUrl动态生成下拉列表的包含。如果您使用form editing修改网格数据,则可以使用beforeInitData代替beforeShowFormdataUrl修改为'<%= ResolveUrl("~/Admin/GetRoles/") %>' + $("#list").jqGrid('selrow') 之前表格将填写。在您可以简化代码的方式中,使ajax请求异步,并且将值设置为下拉控件的问题将自动解决。

相关问题