This question is locked. New answers and comments are not allowed.
Hello, sorry for my english, I´m spanish. I use MVC 3 razor aps.net in my project.
How I can place a combobox in a grid to edit the registry to show me the field values in the combobox?
I want that when I click on Edit, in the popup, the values of the field take a combobox that is populated table in my database
SEE atach picture
this is my grid
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Resizable(resizing => resizing.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Sortable(sorting => sorting
.OrderBy(sortOrder => sortOrder.Add(o => o.id).Ascending())
)
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(c => c.id))
.DataBinding(dataBinding => dataBinding
.Server()
.Select("Index", "agendassustitucion")
.Insert("Insertar", "agendassustitucion")
.Update("Editar", "agendassustitucion")
.Delete("Eliminar", "agendassustitucion"))
.Columns(columns =>
{
columns.Bound(o => o.fechasolicitud).Width(10).Title("Solicitada el");
columns.Bound(o => o.mZona.descripcion).Width(100).Title("Zona");
columns.Bound(o => o.mCentro.descripcion).Width(100).Title("Centro");
columns.Bound(o => o.profesional).Width(100).Title("Profesional");
columns.Bound(o => o.solicitadapor).Width(100).Title("Solicitante");
columns.Bound(o => o.medio).Width(50).Title("Medio");
columns.Bound(o => o.incidencia).Width(10).Title("Incidencia");
columns.Bound(o => o.fechas).Width(90).Title("Fechas");
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
}).Width(110).Title("Acciones");
})
.Editable(editing => editing.Mode(GridEditMode.PopUp))
.Pageable()
.Localizable("es-ES")
.Filterable()
)
this is my combobox
@(Html.Telerik().ComboBox()
.Name("AjaxZonas")
.AutoFill(true)
.DataBinding(binding => binding.Ajax().Select("_AjaxZonas", "incidencia"))
.Filterable(filtering =>
{
filtering.FilterMode(AutoCompleteFilterMode.StartsWith);
})
.HighlightFirstMatch(true)
)
this is a part of the controller
//--------------------------------------------------------------------------------------------
// Para cargar el combobox con las zonas básicas
//--------------------------------------------------------------------------------------------
[HttpPost]
public ActionResult _AjaxZonas(string text)
{
using (entities)
{
var zonas = entities.mZona.AsQueryable();
if (text.HasValue())
{
zonas = zonas.Where((p) => p.descripcion.StartsWith(text));
}
return new JsonResult { Data = new SelectList(zonas.ToList(), "codigo", "descripcion") };
}
}
[HttpPost]
public ActionResult _AutoCompleteAjaxZonas(string text)
{
using (entities)
{
var zonas = entities.mZona.AsQueryable();
if (text.HasValue())
{
zonas = zonas.Where((p) => p.descripcion.StartsWith(text));
}
return new JsonResult { Data = zonas.Select(p => p.descripcion).ToList() };
}
}
How I can place a combobox in a grid to edit the registry to show me the field values in the combobox?
I want that when I click on Edit, in the popup, the values of the field take a combobox that is populated table in my database
SEE atach picture
this is my grid
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Resizable(resizing => resizing.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Sortable(sorting => sorting
.OrderBy(sortOrder => sortOrder.Add(o => o.id).Ascending())
)
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(c => c.id))
.DataBinding(dataBinding => dataBinding
.Server()
.Select("Index", "agendassustitucion")
.Insert("Insertar", "agendassustitucion")
.Update("Editar", "agendassustitucion")
.Delete("Eliminar", "agendassustitucion"))
.Columns(columns =>
{
columns.Bound(o => o.fechasolicitud).Width(10).Title("Solicitada el");
columns.Bound(o => o.mZona.descripcion).Width(100).Title("Zona");
columns.Bound(o => o.mCentro.descripcion).Width(100).Title("Centro");
columns.Bound(o => o.profesional).Width(100).Title("Profesional");
columns.Bound(o => o.solicitadapor).Width(100).Title("Solicitante");
columns.Bound(o => o.medio).Width(50).Title("Medio");
columns.Bound(o => o.incidencia).Width(10).Title("Incidencia");
columns.Bound(o => o.fechas).Width(90).Title("Fechas");
columns.Command(commands =>
{
commands.Edit();
commands.Delete();
}).Width(110).Title("Acciones");
})
.Editable(editing => editing.Mode(GridEditMode.PopUp))
.Pageable()
.Localizable("es-ES")
.Filterable()
)
this is my combobox
@(Html.Telerik().ComboBox()
.Name("AjaxZonas")
.AutoFill(true)
.DataBinding(binding => binding.Ajax().Select("_AjaxZonas", "incidencia"))
.Filterable(filtering =>
{
filtering.FilterMode(AutoCompleteFilterMode.StartsWith);
})
.HighlightFirstMatch(true)
)
this is a part of the controller
//--------------------------------------------------------------------------------------------
// Para cargar el combobox con las zonas básicas
//--------------------------------------------------------------------------------------------
[HttpPost]
public ActionResult _AjaxZonas(string text)
{
using (entities)
{
var zonas = entities.mZona.AsQueryable();
if (text.HasValue())
{
zonas = zonas.Where((p) => p.descripcion.StartsWith(text));
}
return new JsonResult { Data = new SelectList(zonas.ToList(), "codigo", "descripcion") };
}
}
[HttpPost]
public ActionResult _AutoCompleteAjaxZonas(string text)
{
using (entities)
{
var zonas = entities.mZona.AsQueryable();
if (text.HasValue())
{
zonas = zonas.Where((p) => p.descripcion.StartsWith(text));
}
return new JsonResult { Data = zonas.Select(p => p.descripcion).ToList() };
}
}