2012-07-31 50 views
0

我正在嘗試使用JQgrid並編輯我的對象。但是,我不知道如何將參數傳遞給服務器端代碼。這是我的jq代碼:將參數傳遞給jqGrid編輯行上的服務器端代碼

jQuery("#tblList").jqGrid({ 
      url: 'CityList.aspx/GetList', 
      editurl: 'CityList.aspx/GetList', 
      mtype: 'POST', 
      datatype: 'json', 
      postData: { searchString: '', searchField: '', searchOper: '' }, 
      ajaxGridOptions: { contentType: "application/json" }, 
      serializeGridData: function (postData) { 
       var propertyName, propertyValue, dataToSend = {}; 
       for (propertyName in postData) { 
        if (postData.hasOwnProperty(propertyName)) { 
         propertyValue = postData[propertyName]; 
         if ($.isFunction(propertyValue)) { 
          dataToSend[propertyName] = propertyValue(); 
         } else { 
          dataToSend[propertyName] = propertyValue 
         } 
        } 
       } 
       return JSON.stringify(dataToSend); 
      }, 
      jsonReader: { 
       root: "d.rows", 
       page: "d.page", 
       total: "d.total", 
       records: "d.records" 
      }, 
      colNames: ['Id', 'Şehir Adı'], 
      colModel: [ 
       { name: 'CityId', index: 'CityId', hidden: true }, 
       { name: 'Name', index: 'Name', width: 400, editable: true, edittype: 'text' } 
      ], 
      ondblClickRow: function (id) { alert("You double click row with id: " + id); }, 
      pager: '#tblPager', 
      rowList: [10, 20, 30], 
      sortname: 'CityId', 
      sortorder: 'desc', 
      rowNum: 10, 
      loadtext: "Yukleniyor....", 
      shrinkToFit: false, 
      multiselect: false, 
      emptyrecords: "Kayit Bulunamadi", 
      autowidth: true, 
      shrinkToFit: true, 
      height: "400", 
      rownumbers: true, 
      //subGrid: true, 
      caption: 'Şehirler' 
     }).navGrid('#tblPager', { add: true, edit: true, del: true, reload: true }); 

    }); 
    jQuery("#tblList").editGridRow(rowid, properties); 

我是jqGrid的新手,你能告訴我如何編輯我的記錄嗎?

回答

0

我成立了DataRequesting事件:

代碼behind-

public void JQGridVets_DataRequesting(object sender, JQGridDataRequestEventArgs e) 
    { 
     ObjectDataSourceVets.SelectParameters["BusID"].DefaultValue = e.ParentRowKey; 
     ObjectDataSourceVets.InsertParameters["BusID"].DefaultValue = e.ParentRowKey; 
    } 
在aspx文件

- 在ObjectDataSource控件指定

<asp:ObjectDataSource ID="ObjectDataSourceVets" runat="server" 
     SelectMethod="GetVetAll" TypeName="AHP.Data.PhoneBookRepository" 
     UpdateMethod="UpdateVet" InsertMethod="InsertVet" 
     OldValuesParameterFormatString="original_{0}" > 
     <InsertParameters> 
      <asp:Parameter Name="FirstName" Type="String" /> 
      <asp:Parameter Name="M" Type="String" /> 
      <asp:Parameter Name="LastName" Type="String" /> 
      <asp:Parameter Name="vetphone" Type="String" /> 
      <asp:Parameter Name="vetemail" Type="String" /> 
      <asp:Parameter Name="Degree" Type="String" /> 
      <asp:Parameter Name="License" Type="String" /> 
      <asp:Parameter Name="Code" Type="String" /> 
      <asp:Parameter Name="BusID" Type="String" /> 
      <asp:Parameter Name="oper" Type="String" /> 
      <asp:Parameter Name="id" Type="String" /> 
     </InsertParameters> 
     <SelectParameters> 
      <asp:Parameter Name="BusID" Type="String" /> 
     </SelectParameters> 
     <UpdateParameters> 
      <asp:Parameter Name="FirstName" Type="String" /> 
      <asp:Parameter Name="M" Type="String" /> 
      <asp:Parameter Name="LastName" Type="String" /> 
      <asp:Parameter Name="vetphone" Type="String" /> 
      <asp:Parameter Name="vetemail" Type="String" /> 
      <asp:Parameter Name="Degree" Type="String" /> 
      <asp:Parameter Name="License" Type="String" /> 
      <asp:Parameter Name="Code" Type="String" /> 
      <asp:Parameter Name="VetID" Type="String" /> 
     </UpdateParameters> 
    </asp:ObjectDataSource> 

所以在InsertMethod的busid有正確的價值。

這用於從子網格添加子記錄。

相關問題