在尝试向每个动态列表项添加复选框时使用JSON

时间:2012-09-24 18:27:08

标签: javascript asp.net json

我正在尝试使用前面的复选框填充行,因为它是动态构建的。 我是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' }
            ],

1 个答案:

答案 0 :(得分:0)

想通了:

jsonWriter.WritePropertyName("checkbox");
      jsonWriter.WriteValue("<input class=\"exhibitMoveCheckBox\" id=\"exhibitMoveCheckBox_"+reader["ExhibitID"].ToString()+"\" type=\"checkbox\">");