Friday, November 14, 2014

Set the datasource item to the value of a templated control

You have a template control like this:


c.Template(r => r.drugID).ClientTemplate("# if ( drugID == 2) { #" +
 "<select id='dlIVConcentration' class='gridClientTemplate4' disabled='disabled'>" +
 "<option value='1' " + " #if (concentration < 500) {#" + "selected" + "#}#>Please Select</option>" +
 "<option value='2500' " + " #if (concentration == 2500) {#" + "selected" + "#}#>2,500</option>" +
 "<option value='5000' " + " #if (concentration == 5000) {#" + "selected" + "#}#>5,000</option>" +
 "<option value='10000' " + " #if (concentration == 10000) {#" + "selected" + "#}#>10,000</option>" +
 "<option value='150000' " + " #if (concentration == 105000) {#" + "selected" + "#}#>105,000</option>" + "</select>" +
 "# } else {#" +
 "<input type='text' onkeypress='return isNumberKey(event)' class='gridClientTemplate4' disabled='disabled' id='tbIVConcentration' value='#= (concentration || '') #' /> " +
 "# }#").Width(150).Title("Concentration").HeaderHtmlAttributes(new { title = "Concentration" });

In order to save the selected value when the record is saved, bind to the save event something like this in JavaScript:


var grid = $("#ivdosegrid").data("kendoGrid");

 var tr = grid.select().closest("tr");

  var dataItem = grid.dataItem(tr);

 dataItem.concentration = $("#dlIVConcentration").val();

No comments:

Post a Comment