0
和所使用的腳本是
<script type="text/javascript">
var lastSelection;
var idCategoria;
var nomeCategoria;
function editRow(id) {
if (id && id !== lastSelection) {
var grid = jQuery("#<%= JQGrid1.ClientID %>");
if (document.getElementById(lastSelection + "_NomeCategoria") != null) {
if (document.getElementById(lastSelection + "_NomeCategoria").value != undefined) {
var objeto = document.getElementById(lastSelection + "_NomeCategoria");
idCategoria = objeto.value;
nomeCategoria = objeto[objeto.selectedIndex].text;
}
}
if (lastSelection != undefined) {
grid.updateGridRows("{IdCategoria:" + idCategoria + "}", lastSelection);
grid.saveRow(lastSelection, false);
//grid.setCell(lastSelection, "IdCategoria", idCategoria);
//grid.setRowData(lastSelection, "{IdCategoria:" + idCategoria + "}");
}
try
{
grid.restoreRow(lastSelection, defineCategoria);
}
catch(err)
{
alert(err.description);
}
grid.editRow(id, true, selecionaCategoria);
lastSelection = id;
}
}
function selecionaCategoria(id) {
var grid = jQuery("#<%= JQGrid1.ClientID %>");
var linha = grid.getRowData(id);
var idCategoria = linha.IdCategoria;
var comboCategorias = document.getElementById(id + "_NomeCategoria");
if (idCategoria != "" && idCategoria != undefined) {
try {
for (var i = 0; i < comboCategorias.childNodes.length; i++) {
if (comboCategorias.childNodes[i].value == idCategoria) {
comboCategorias.childNodes[i].selected = true;
break;
}
}
}
catch (err) {
alert(err.description);
}
}
}
function defineCategoria(id) {
var grid = jQuery("#<%= JQGrid1.ClientID %>");
grid.setCell(id, "NomeCategoria", DefineUrlCategoria(idCategoria, nomeCategoria));
}
// The FormatFunction for CustomFormatter gets three parameters
// cellValue - the original value of the cell
// options - as set of options, e.g
// options.rowId - the primary key of the row
// options.colModel - colModel of the column
// rowData - array of cell data for the row, so you can access other cells in the row if needed
function DefineUrl(cellValue, options, rowObject) {
var caminho = "";
if (isArray(rowObject)) {
if (rowObject[1] != "" && rowObject[1] != undefined) {
//var caminho = "<a href='/Ferramenta/Graficos/GraficoCategoria.aspx?idCategoria=" + rowObject[1] + "'>" + cellValue + "</a>";
caminho = DefineUrlCategoria(rowObject[1], cellValue);
}
else {
caminho = cellValue;
}
}
else {
if (idCategoria != "0") {
caminho = DefineUrlCategoria(idCategoria, nomeCategoria);
}
else {
caminho = nomeCategoria;
}
}
return caminho;
}
function isArray(o) {
return (typeof (o.length) == "undefined") ? false : true;
}
function DefineUrlCategoria(idCategoria, nomeCategoria) {
var caminho = "<a href='/Ferramenta/Graficos/GraficoCategoria.aspx?idCategoria=" + idCategoria + "'>" + nomeCategoria + "</a>";
return caminho;
}
</script>
當行不處於編輯模式時,第五列顯示鏈接,並在編輯時顯示下拉列表。要在下拉列表中選擇正確的項目,我使用具有來自數據庫的ID的第二列。
問題是,更改項目並將其保存到數據庫後,此列值不會更改。我怎麼能在grid.saveRow(lastSelection,false)之後做到這一點; ?
謝謝。