This question is locked. New answers and comments are not allowed.
hello i have a problem when i try to implement combo box in grid. i have grid with 4 filed. on of them is combo box and when i click in this filed it not fire the event OnEdit. the other filds fire the event.
what i do is :
in class model :
in DDLAsmahtaType :
in SelectAsmahtaType in the control Tik :
and the grid :
thanks for help.
what i do is :
in class model :
public long filed1 { get; set; } public decimal? filed2 { get; set; } public decimal? filed3 { get; set; } [UIHint("DDLAsmahtaType"), Required] public EditAsmahtaType filed3 { get; set; }
in DDLAsmahtaType :
@(Html.Telerik().ComboBox() .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)) .DataBinding(binding => binding.Ajax().Select("_SelectAsmahtaType", "Tik")))
in SelectAsmahtaType in the control Tik :
[HttpPost] public ActionResult _SelectAsmahtaType() { List<SelectListItem> ListData = new List<SelectListItem>(); ListData.Add(new SelectListItem() { Selected = true, Text = "Choose1", Value = "0" }); ListData.Add(new SelectListItem() { Selected = false, Text = "Choose2", Value = "1" }); return new JsonResult { Data = new SelectList(ListData.ToList(), "Value", "Text") }; }
and the grid :
@(Html.Telerik().Grid<LawyerAccountDTL>( ) .Name("Grid") .DataKeys(keys => { keys.Add(o => o.AccountId); }) .ToolBar(commands => { commands.Insert(); commands.SubmitChanges(); }) .DataBinding(dataBinding => { dataBinding.Ajax() .Select("InsertTakbulimAjax", "Tik") .Update("_SaveBatchEditing", "Tik"); }) .Columns(Cols => { Cols.Bound(Col => Col.Filed1) .Format("{0:g}") .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" }) .HtmlAttributes(new { @id = "Grid_Row" }) .Title("1 ") .Sortable(true) .Width("14%"); Cols.Bound(Col => Col.Filed2) .Format("{0:g}") .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" }) .HtmlAttributes(new { @id = "Grid_Row" }) .Title("1 ") .Sortable(true) .Width("14%"); Cols.Bound(Col => Col.Filed3) .Format("{0:g}") .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" }) .HtmlAttributes(new { @id = "Grid_Row" }) .Title("1 ") .Sortable(true) .Width("14%"); Cols.Bound(Col => Col.DDLAsmahtaType) .ClientTemplate("<#= DDLAsmahtaType.AsmahtaName #>").Width(230) .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" }) .Sortable(false) .HtmlAttributes(new { @id = "Grid_Row" }) .ReadOnly() .Title("סוג אסמכתא ") .Width("23%"); }) .ClientEvents(events => events.OnDataBinding("Grid_onDataBinding").OnEdit("Grid_OnEdit").OnSave("Grid_OnSave")) .Editable(editing => editing.Mode(GridEditMode.InCell)) .Pageable() )
<script type="text/javascript"> function Grid_onDataBinding(e) { alert('1'); var grid = $(this).data('tGrid'); if (grid.hasChanges()) { if (!confirm('You are going to lose any unsaved changes. Are you sure?')) { e.preventDefault(); } } } function Grid_OnEdit(e) { alert('2'); var $combo = $(e.cell).find('#Employee'); if ($combo.length > 0) { var combo = $combo.data('tComboBox'); combo.fill(function () { combo.value(e.dataItem['Employee'].EmployeeID) }); } } function Grid_OnSave(e) { alert('ddsssssddd'); var $combo = $(e.cell).find('#Employee'); if ($combo.length > 0) { var combo = $combo.data("tComboBox"), selectItem = combo.selectedIndex > -1 ? combo.data[combo.selectedIndex] : null; if (selectItem) { var splitName = selectItem.Text.split(" "); e.values["Employee"] = { EmployeeID: selectItem.Value || selectItem.Text, FirstName: splitName[0], LastName: splitName[1] }; } else { var value = combo.value(); e.values["Employee"] = { EmployeeID: value, FirstName: value, LastName: value }; } } } </script>
thanks for help.