internal static JsonResponse PrepareJsonResponse(JsonResponse response, JQGrid grid, DataTable dt) { for (int i = 0; i < dt.Rows.Count; i++) { string[] array = new string[grid.Columns.Count]; for (int j = 0; j < grid.Columns.Count; j++) { JQGridColumn jQGridColumn = grid.Columns[j]; string text = ""; if (!string.IsNullOrEmpty(jQGridColumn.DataField)) { Guard.IsNull(dt.Columns[jQGridColumn.DataField], "The column with DataField=" + jQGridColumn.DataField + " does not exist in the datasource."); int ordinal = dt.Columns[jQGridColumn.DataField].Ordinal; text = (string.IsNullOrEmpty(jQGridColumn.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : jQGridColumn.FormatDataValue(dt.Rows[i].ItemArray[ordinal], jQGridColumn.HtmlEncode)); } array[j] = text; } string text2 = array[Util.GetPrimaryKeyIndex(grid)]; for (int k = 0; k < grid.Columns.Count; k++) { JQGridCellBindEventArgs jQGridCellBindEventArgs = new JQGridCellBindEventArgs(array[k], k, i, text2, dt.Rows[i].ItemArray); grid.OnCellBinding(jQGridCellBindEventArgs); array[k] = jQGridCellBindEventArgs.CellHtml; grid.OnCellBound(jQGridCellBindEventArgs); } JsonRow jsonRow = new JsonRow(); jsonRow.id = text2; jsonRow.cell = array; response.rows[i] = jsonRow; } return(response); }