This is a migrated thread and some comments may be shown as answers.

Combobox for enum object type

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
arnorgauti
Top achievements
Rank 1
arnorgauti asked on 15 Mar 2012, 10:28 AM
Hi

I'm using.

http://demos.telerik.com/aspnet-mvc/razor/Grid/EditingServerSide

for demo and working with object that contains enum type. The question is when i edit the line (in serverSide), how can i have a drop down list where i can choose from this enum type in edit mode ?

sincerly
agh

2 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 15 Mar 2012, 12:31 PM
Hi,

Try something like this :

Html.Telerik().Grid<MyModelType>()
           
.Name("Grid")                      
           
.Columns(columns =>
           
{
               
columns.ForeignKey(o => o.MyEnumProperty, (IEnumerable)Enum.GetNames(typeof(MyEnumType)).Select(s=>new SelectListItem{Text = s, Value = s}),
                   
"ID", "Name")
.Width(230);             
           
})     This will give you a dropdown list in update mode. Regards,
0
JORGE
Top achievements
Rank 1
answered on 11 Oct 2012, 05:27 PM
I´m triyng to build a example similar, but I didn´t wrong. "DOESN´T WORK!!!"

Can you help me please?

I have this:


\\VIEW
@(Html.Telerik().Grid(Model)
     .Name("Grid")
     .Localizable("pt-BR")
     .DataKeys(keys =>
     {    
         keys.Add(c => c.USR_CD);  
     })
             .ToolBar(commands => commands.Insert().ButtonType(type)
                 .ImageHtmlAttributes(new { style = "margin-left:0" }))
  
             .DataBinding(databinding =>
             {
                 databinding.Server()
                 .Select("Index", "Usuarios")
                 .Update("Edit", "Usuarios")
                 .Delete("Delete", "Usuarios")
                 .Insert("Create", "Usuarios");
  
   
             })
               
     .Columns(c => 
            {
            c.Bound(o => o.USR_CD).Width(60).Title("Código");
            c.Bound(o => o.USR_NOME).Width(300).Title("Nome");
            c.Bound(o => o.USR_LOGIN).Width(300).Title("Login");
            //c.Bound(o => o.USR_UF).Width(100).Title("UF");
            c.ForeignKey(o => o.USR_UF, ViewBag.UF as SelectList).Width(100);
            c.Bound(o => o.USR_STATUS).Width(100).Title("Status");
  
            c.Command(cmd =>
                      {
                          cmd.Edit().ButtonType(type);
                          cmd.Delete().ButtonType(type);
                      }).Width(180).Title("Altera/Deleta"); 
          })
      .Editable(editing => editing.Mode(mode))  
      .Pageable(paging => paging.PageSize(10))
      .Sortable()
      .Footer(true)
      .NoRecordsTemplate("Sem Registro")
      .Resizable(resizing => resizing.Columns(true))
      .Filterable(filtering => filtering.Enabled(true))
      .Groupable(grouping => grouping.Enabled(false)) 
      .HtmlAttributes(new { style = " font-family:arial; font-size: .9em; font-weight: bold;" })
  




\\CLASS
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace STC_WEB.Models
{
    public partial class USR_USUARIOS
    {
        public USR_USUARIOS()
        {
            this.CLI_CLIENTES = new HashSet<CLI_CLIENTES>();
            this.CON_CTRC = new HashSet<CON_CTRC>();
            this.CTR_CTRB = new HashSet<CTR_CTRB>();
            this.MOT_MOTORISTAS = new HashSet<MOT_MOTORISTAS>();
            this.NTC_NOTAFCON = new HashSet<NTC_NOTAFCON>();
            this.NTS_NOTASERV = new HashSet<NTS_NOTASERV>();
            this.SYS_LOG = new HashSet<SYS_LOG>();
            this.SYS_USR_CONFIGURACAO = new HashSet<SYS_USR_CONFIGURACAO>();
            this.TAB_TABECLI = new HashSet<TAB_TABECLI>();
            this.TMV_MARVEICULO = new HashSet<TMV_MARVEICULO>();
            this.VEI_VEICULOS = new HashSet<VEI_VEICULOS>();
        }
      
        public int USR_CD { get; set; }
        public string USR_LOGIN { get; set; }
        public string USR_PASSWORD { get; set; }
        public string USR_NOME { get; set; }
         
        //[UIHint("USR_UF"), Required]
        //public SYS_UF SYS_UF_CD { get; set; }
         
        public string USR_UF { get; set; }
        public string USR_CONTATOEMAIL { get; set; }
        public bool USR_STATUS { get; set; }
      
        public virtual ICollection<CLI_CLIENTES> CLI_CLIENTES { get; set; }
        public virtual ICollection<CON_CTRC> CON_CTRC { get; set; }
        public virtual ICollection<CTR_CTRB> CTR_CTRB { get; set; }
        public virtual ICollection<MOT_MOTORISTAS> MOT_MOTORISTAS { get; set; }
        public virtual ICollection<NTC_NOTAFCON> NTC_NOTAFCON { get; set; }
        public virtual ICollection<NTS_NOTASERV> NTS_NOTASERV { get; set; }
        public virtual ICollection<SYS_LOG> SYS_LOG { get; set; }
        public virtual ICollection<SYS_USR_CONFIGURACAO> SYS_USR_CONFIGURACAO { get; set; }
        public virtual ICollection<TAB_TABECLI> TAB_TABECLI { get; set; }
        public virtual ICollection<TMV_MARVEICULO> TMV_MARVEICULO { get; set; }
        public virtual ICollection<VEI_VEICULOS> VEI_VEICULOS { get; set; }
        public virtual ACE_ACESSOS ACE_ACESSOS { get; set; }
  
        internal static object All()
        {
            throw new NotImplementedException();
        }
    }
  
 )
   
\\MODEL
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Entity;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using STC_WEB.Models;
    using Telerik.Web.Mvc;
      
    namespace STC_WEB.Controllers
    
        public class UsuariosController : Controller
        {
            private AGRELENSEEntities db = new AGRELENSEEntities();
      
            //
            // GET: /Usuarios/
      
            public ViewResult Index()
            {
                  var ESTADO = db.SYS_UF.AsQueryable();
      
                   ViewBag.UF = new SelectList(ESTADO.ToList(), "SYS_UF_CD", "SYS_UF_CD");
      
                   return View(db.USR_USUARIOS.ToList());
            }
      
            //
            // GET: /Usuarios/Details/5
      
            public ViewResult Details(int id)
            {
                USR_USUARIOS usr_usuarios = db.USR_USUARIOS.Find(id);
                return View(usr_usuarios);
            }
      
            //
            // GET: /Usuarios/Create
      
            public ActionResult Create()
            {
                return View();
            
      
            //
            // POST: /Usuarios/Create
      
            [HttpPost]
            public ActionResult Create(USR_USUARIOS usr_usuarios)
            {
                if (ModelState.IsValid)
                {
                    db.USR_USUARIOS.Add(usr_usuarios);
                    db.SaveChanges();
                    return RedirectToAction("Index");  
                }
      
                return View(usr_usuarios);
            }
              
            //
            // GET: /Usuarios/Edit/5
       
            public ActionResult Edit(int id)
            {
                USR_USUARIOS usr_usuarios = db.USR_USUARIOS.Find(id);
                return View(usr_usuarios);
            }
      
            //
            // POST: /Usuarios/Edit/5
      
            [HttpPost]
            public ActionResult Edit(USR_USUARIOS usr_usuarios)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(usr_usuarios).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(usr_usuarios);
            }
      
            //
            // GET: /Usuarios/Delete/5
       
            public ActionResult Delete(int id)
            {
                USR_USUARIOS usr_usuarios = db.USR_USUARIOS.Find(id);
                return View(usr_usuarios);
            }
      
            //
            // POST: /Usuarios/Delete/5
      
            [HttpPost, ActionName("Delete")]
            public ActionResult DeleteConfirmed(int id)
            {            
                USR_USUARIOS usr_usuarios = db.USR_USUARIOS.Find(id);
                db.USR_USUARIOS.Remove(usr_usuarios);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
      
            protected override void Dispose(bool disposing)
            {
                db.Dispose();
                base.Dispose(disposing);
            }
        }
}

  

Tags
Grid
Asked by
arnorgauti
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
JORGE
Top achievements
Rank 1
Share this question
or