将JqGrid的数据保存到数据库中 [英] Save the data of JqGrid into database
问题描述
大家好,
我是JqGrid中的新蜜蜂....我有一个要求我需要一个JQGrid,每行定制列意味着我有一些复选框,文本框和文本区......现在的事情是我能够正确加载我的JqGrid ,,,但问题是如何将这个jqgrid保存到db ,,意味着我需要JqGrid的值在VB页面上通过ajax调用。
这是我的代码
Hi All,
I am new bee in the JqGrid.... I have one requirement I need one JQGrid with the customized columns means in each row I have some check boxes, textboxes and text area...... Now the thing is I am able to load my JqGrid properly,,, but the problem is how to save this jqgrid into db,, means I need the values of JqGrid on VB page by ajax Call.
Here is my code
function AssayPageBatchAndSample() {
// BatchQCGrid
// StainAcceptedGridView
var accessionId = $("[id*='AccessionIDhidden']").val();
$("#BatchQCGrid").jqGrid({
datatype: 'json',
colNames: ['Batch ID:"' + accessionId + '"', 'Pos QC', 'Neg QC', 'Pass', 'Fail', 'Repeat?', 'Comments'],
colModel: [
{ name: 'Assay', index: 'Assay',width:50},
{ name: 'PosQC', index: 'PosQC', width: 50 },
{ name: 'NegQC', index: 'NegQC', width: 50 },
{ name: 'Pass', index: 'Pass', formatter: showPassCheckbox, width: 50 },
{ name: 'Fail', index: 'Fail', formatter: showFailCheckbox, width: 50 },
{ name: 'Repeat', index: 'Repeat', formatter: showRepeatCheckbox, width: 50 },
{ name: 'Comments', index: 'Comments', formatter: cmntBatchQcComments, Width:300 }
],
multiselect: false,
emptyrecords: "No records to view",
pgbuttons: false,
viewrecords: true,
loadonce: true,
altRows: true,
height: 'auto'
});
dArray = "{";
dArray += "'caseNo': '" + caseno + "',";
dArray += "'rqstMsg': '" + hdnsession + "'";
dArray += "}";
$.ajax({
type: "POST",
url: "../../../../ClientSide-Services/Assay.asmx/GetBatchQcData",
data: dArray,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function(response) {
if (response.d != '{"Table" : ]}') {
var gd = eval('(' + response.d + ')');
for (row in gd) {
$("#BatchQCGrid").jqGrid('addRowData', row, gd[row]);
}
$("#BatchQCGrid").trigger("reloadGrid");
}
else {
$("#BatchQCGrid").jqGrid("clearGridData", true).trigger("reloadGrid");
}
},
error: function(response) {
alert(response.responseText);
}
});
$('[id*="InputToolbarSave"]').click(function() {
alert("In Save button assay");
var gridData = jQuery("#BatchQCGrid").getRowData();
var postData = JSON.stringify(gridData);
alert("JSON serialized jqGrid data:n" + postData);
$.ajax({
type: "POST",
url: preFixUrl + "ClientSide-Services/Common_WS.asmx/Test",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{ gridData: '" + postData + "' }",
async: false,
success: function() {
},
error: function(response) {
alert(response.responseText);
}
});
});
} //End
function showPassCheckbox(cellValue, options, rowobject, action) {
var a = "<input type='checkbox' id='chkPasscheckbox' ></input>";
return a;
}
function showFailCheckbox(cellValue, options, rowobject, action) {
var a = "<input type='checkbox' id='chkFailcheckbox'></input>";
return a;
}
function showRepeatCheckbox(cellValue, options, rowobject, action) {
var a = "<input type='checkbox' id='chkRepeatcheckbox'></input>";
return a;
}
function cmntBatchQcComments(cellValue, options, rowobject, action) {
return "<textarea rows='5' cols='20' id='BatchQcComments' >" +rowobject.Comments+ "</textarea>";
}
************************ asmx.vb页面** ************************************************** ******
************************asmx.vb page **********************************************************
<WebMethod()> _
Public Function GetBatchQcData(ByVal rqstMsg As String, ByVal caseNo As String) As String
Try
Dim bs As New BatchingService.Batching
Dim os As New OrderingService.Ordering
Dim batchData As DataSet
rqstMsg = Decrypt(rqstMsg)
Dim apCase As OrderingService.ApCase = os.ApCase_Get(caseNo, False, rqstMsg)
batchData = bs.BatchQC_Get(apCase.TestOrders(0).Batch.ID, rqstMsg)
Return Common.GetJSONString(batchData.Tables(0))
Catch ex As Exception
Throw (ex)
End Try
End Function
<WebMethod()> _
Public Function Test(ByVal gridData As String)
Try
'Dim jsonSerializer As New JavaScriptSerializer()
'Dim testData As Object
'testData = CType(jsonSerializer.Deserialize(gridData), Object)
Dim testData As Object = New JavaScriptSerializer().Deserialize(Of Object)(gridData)
Catch ex As Exception
Throw (ex)
End Try
End Function
推荐答案
([id * ='AccessionIDhidden'])。val();
("[id*='AccessionIDhidden']").val();
(#BatchQCGrid)。jqGrid({
datatype:'json',
colNames:[ '批次ID:'+ accessionId +'','Pos QC','Neg QC','Pass','Fail','Repeat?','Comments'],
colModel:[
{name:'Assay',index:'Assay',width:50},
{name:'PosQC',index:'PosQC',width:50},
{name:' NegQC',索引:'NegQC',宽度:50},
{名称:'通过',索引:'通过',格式化程序:showPassCheckbox,宽度:50},
{名称:'失败' ,index:'Fail',formatter:showFailCheck box,width:50},
{name:'Repeat',index:'Repeat',formatter:showRepeatCheckbox,width:50},
{name:'Comments',index:'Comments', formatter:cmntBatchQcComments,宽度:300}
],
multiselect:false,
emptyrecords:没有要查看的记录,
pgbuttons:false,
viewrecords:true ,
loadonce:true,
altRows:true,
height:'auto'
});
dArray ={;
dArray + ='caseNo':'+ caseno +',;
dArray + ='rqstMsg':'+ hdnsession +';
dArray + =};
("#BatchQCGrid").jqGrid({ datatype: 'json', colNames: ['Batch ID:"' + accessionId + '"', 'Pos QC', 'Neg QC', 'Pass', 'Fail', 'Repeat?', 'Comments'], colModel: [ { name: 'Assay', index: 'Assay',width:50}, { name: 'PosQC', index: 'PosQC', width: 50 }, { name: 'NegQC', index: 'NegQC', width: 50 }, { name: 'Pass', index: 'Pass', formatter: showPassCheckbox, width: 50 }, { name: 'Fail', index: 'Fail', formatter: showFailCheckbox, width: 50 }, { name: 'Repeat', index: 'Repeat', formatter: showRepeatCheckbox, width: 50 }, { name: 'Comments', index: 'Comments', formatter: cmntBatchQcComments, Width:300 } ], multiselect: false, emptyrecords: "No records to view", pgbuttons: false, viewrecords: true, loadonce: true, altRows: true, height: 'auto' }); dArray = "{"; dArray += "'caseNo': '" + caseno + "',"; dArray += "'rqstMsg': '" + hdnsession + "'"; dArray += "}";
.ajax({
type:POST,
url:../../。 ./../ClientSide-Services/Assay.asmx/GetBatchQcData,
data:dArray,
contentType:application / json; charset = utf-8,
dataType:json ,
async:false,
成功:函数(响应){
if(response.d!='{Table:]}'){
var gd = eval('('+ response.d +')');
for(gd中的行){
.ajax({ type: "POST", url: "../../../../ClientSide-Services/Assay.asmx/GetBatchQcData", data: dArray, contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function(response) { if (response.d != '{"Table" : ]}') { var gd = eval('(' + response.d + ')'); for (row in gd) {
这篇关于将JqGrid的数据保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!