我想在后面的代码中访问所选的行单元格id。我可以通过Ajax调用来实现它,但是当我尝试从Jqgrid子网格发送数据时它是不可能的。
以下是子网格代码:
subGridRowExpanded: function (subgrid_id, row_id) {
debugger;
var subgrid_table_id, pager_id; subgrid_table_id = subgrid_id + "_t";
var selected_row_id = $('#tblFormData').jqGrid('getCell', row_id, 'Category_Id')
// pager_id = "p_" + subgrid_table_id;
$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + pager_id + "' class='scroll'></div>");
$("#" + subgrid_table_id).jqGrid({
// $("#tblTest").jqGrid({
url: "/Forms.aspx/GetFormsData", //?selected_row_id=" + selected_row_id,
data: '{"CategoryDesc":"' + selected_row_id + '"}',
datatype: "json",
contentType: "application/json; charset=utf-8",
loadonce: true,
width: "300",
height: "auto",
pager:"#tblSubpager",
colNames: ['FormName','FormPath'],
colModel: [
{ name: "FormName", index: "FormName", editable: true, formatter: 'showlink' },
//{ name: "FormPath", index: "FormPath", editable: true, hidden: true },
{
name: 'FormPath',
index: 'FormPath',
hidden: true,
enctype: "multipart/form-data",
editable: true,
edittype: 'file',
editrules: {
edithidden: true,
required: true
},
formoptions: {
elmsuffix: '*'
}
}
],
gridview: true,
autoencode: true,
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj.d; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.d.length; }
}
});
&#13;
下面是我从Vb.NET中的URL调用它的函数。
<WebMethod> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function GetFormsData(CategoryId As String) As List(Of Dictionary(Of String, String))
Using dt As DataTable = DirectCast(DataAccess.ExecuteStoredProcedure("AFI_DYNAMIC", "Ashley.dbo.usp_GetDownloadFormsDetails", DataAccess.StoredProcedureReturnType.DataTable), DataTable)
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows1 As New List(Of Dictionary(Of String, String))()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object)
Dim row1 As Dictionary(Of String, String)
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
row1 = New Dictionary(Of String, String)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
'string sb = "<a href=\"http://www.yahoo.com\" title=\"Yahoo!\">Yahoo!</a>";
Next
rows.Add(row)
'For i As Integer = 0 To dt.Columns.Count - 1
Dim sb As String = "<a href=" & """" & dr("FormPath").ToString() & """" & ">" & dr("FormName").ToString() & "</a>"
'Next
row1.Add(dt.Columns(0).Caption, sb)
rows1.Add(row1)
Next
Return rows1
End Using
End Function
&#13;
现在我想在我的代码中访问CategoryId。任何人都可以帮助我。
答案 0 :(得分:0)
代码清楚了许多问题。我在下面发布一些明显的问题,我可以通过阅读代码找到:
CategoryId
吗? $('#tblFormData')
是父网格吗?在这种情况下,您可以使用$(this)
代替$('#tblFormData')
。pager_id
作为寻呼机的id
<div>
用于子网格,但为pager_id
分配值的行已注释,ID为{{1} }。而不是你使用错误的undefined
。pager:"#tblSubpager"
参数。所以你应该删除它。而不是将contentType
参数与ajaxGridOptions
一起使用。这是正确的参数。contentType
但服务器代码期望参数的名称为data: '{"CategoryDesc":"' + selected_row_id + '"}',
,而不是CategoryId
。顺便说一句,jqGrid在使用CategoryDesc
的情况下没有data
参数。你的意思应该是datatype: "json"
。正确的将是使用postData