0

我正在尝试用前面的复选框填充一行,因为它是动态构建的。我是 Json 的新手。

这是我动态格式化列的地方:

 while(reader.Read()) {
    if(i>=startRead&&i<maxCount) {
      var actionBtns=new StringBuilder("");
      jsonWriter.WriteStartObject();
      jsonWriter.WritePropertyName("id");
      jsonWriter.WriteValue("a"+i);
      jsonWriter.WritePropertyName("cell");
      jsonWriter.WriteStartObject();



 //trying to add checkboxes here but not sure what to  put as Value????

//need help with this part: i want to add a checkbox here ----------------
      jsonWriter.WritePropertyName("exhibitCheckBox");


      jsonWriter.WritePropertyName("actionBtns");
      jsonWriter.WriteValue(actionBtns.ToString());
      jsonWriter.WritePropertyName("ExhibitMovementID");
      jsonWriter.WriteValue(reader["ExhibitMovementID"].ToString());
      jsonWriter.WritePropertyName("Location");
      jsonWriter.WriteValue(reader["Location"].ToString());
      jsonWriter.WritePropertyName("TrackingNumber");
      jsonWriter.WriteValue(reader["TrackingNumber"].ToString());
      jsonWriter.WritePropertyName("MovedBy");
      jsonWriter.WriteValue(reader["MovedBy"].ToString());
      jsonWriter.WritePropertyName("ShipperName");
      jsonWriter.WriteValue(reader["ShipperName"].ToString());
      jsonWriter.WritePropertyName("ReceiverName");
      jsonWriter.WriteValue(reader["ReceiverName"].ToString());
      jsonWriter.WritePropertyName("Company");
      jsonWriter.WriteValue(reader["Company"].ToString());
      jsonWriter.WritePropertyName("Reason");
      jsonWriter.WriteValue(reader["Reason"].ToString());
      jsonWriter.WriteEndObject();
      jsonWriter.WriteEndObject();
      sb.Append(",");
    }

我的 javascript 中的复选框称为“exhibitCheckBox”:

$('#viewExhibitMoveHistoryGrid').flexigrid({
            url: url,
            dataType: 'json',
            method: 'get',
            colModel: [
            //{ display: 'Actions', name: 'actionBtns', width: 50, sortable: true, align: 'center' },
                {display: '<input type="checkbox" class="exhibitCheckBox" id="checkAllExhibits" />', name: 'checkbox', width: 20, sortable: false, align: 'left', process: caseFileRowSelected },
                { display: 'Move ID', name: 'ExhibitMovementID', width: 100, sortable: true, hide: false, align: 'center' },
                { display: 'Reason', name: 'Reason', width: 120, sortable: true, align: 'center' },
                { display: 'Moved By', name: 'MovedBy', width: 120, sortable: true, align: 'center' },
                { display: 'Moved To', name: 'ExhibitLocation', width: 120, sortable: true, align: 'center' },
                { display: 'Date', name: 'ExhibitMoveDate', width: 100, sortable: true, align: 'center' },
                { display: 'Time', name: 'ExhibitMoveTime', width: 100, sortable: true, align: 'center' },                    
                { display: 'Receiver', name: 'ReceiverName', width: 120, sortable: true, align: 'center' },
                { display: 'Company', name: 'Company', width:120, sortable: true, align: 'center' },
                { display: 'Shipper', name: 'ShipperName', width: 120, sortable: true, align: 'center' },
                { display: 'Tracking #', name: 'TrackingNumber', width: 120, sortable: true, align: 'center' },
                { display: 'Cost', name: 'ShippingCost', width: 120, sortable: true, align: 'center' }
            ],
4

1 回答 1

0

弄清楚了:

jsonWriter.WritePropertyName("checkbox");
      jsonWriter.WriteValue("<input class=\"exhibitMoveCheckBox\" id=\"exhibitMoveCheckBox_"+reader["ExhibitID"].ToString()+"\" type=\"checkbox\">");
于 2012-09-24T19:50:41.477 回答