Dropdownlist problem in Grid

12 posts, 0 answers
  1. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 17 Nov 2015 Link to this post

    I am using a dropdownlist in grid. The value is showing correctly in the column but when I click on the the column, the dropdownlist comes without the selected value. I have attached 3 images.

     

    I need the value to be selected when I will click on the column and the dropdownlist will appear with that value. In my case when I will click on the column, the dropdownlist will appear with "DB" selected. And then I can change another value if I want. How can I do that?

     

     

    Thanks

  2. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 17 Nov 2015 Link to this post

    Here is my code

    @(Html.Kendo().Grid<ServicePROWeb.ServiceProWCFService.GrJscMstr>()
            .Name("gridJobAllocation")
            .Columns(columns =>
            {
                columns.Bound(p => p.gr_sch_date).Title("Date").Format("{0:dd/MMM/yyyy}").Width(120).Locked(true);
                columns.Bound(p => p.gr_sch_time).Title("Time").Width(100).Locked(true);
                columns.Bound(p => p.gr_sch_assto).Title("Tech").Width(150).Locked(true);
                columns.Bound(p => p.gr_ass_time).Title("PL").Width(40).Locked(true).EditorTemplateName("");
     
                columns.Bound(p => p.gr_status)
                .EditorTemplateName("_statusDropDownList")
                .ClientTemplate("#=gr_status#")
                .Title("ST")
                .Width(70);
     
                columns.ForeignKey(p => p.gr_status, (System.Collections.IEnumerable)ViewData["TreatmentCheckBoxes"], "Id", "Status")
                .EditorTemplateName("_statusDropDownList")
                .ClientTemplate("#=gr_status#")
                .Title("ST2")
                .Width(120);
     
                columns.Bound(p => p.gr_runno).Title("Run").Width(100);
                columns.Bound(p => p.gr_freq).Title("SC").Width(80);
                columns.Bound(p => p.gr_prcode).Title("Item").Width(150);                             
            })
            .Events(e =>
            {
                e.DataBound("gridJobAllocation_dataBound");
                e.DataBinding("gridJobAllocation_dataBinding");
            })
            .Editable(e => e.Mode(GridEditMode.InCell))
            .Sortable()
            .Selectable()
            .Scrollable()
            .Resizable(r => r.Columns(true))
            .Reorderable(reorder => reorder.Columns(true))
            .HtmlAttributes(new { @style = "cursor: pointer; height: 550px;" })
            .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .ServerOperation(false)
            .Sort
            (
                s =>
                {
                    s.Add("gr_sch_date").Descending();
                    s.Add("gr_sch_time").Ascending();
                }
            )
            .Model(model =>
            {
                model.Id(o => o.gr_jobno);
                model.Field(o => o.gr_status).DefaultValue("DB");
            })
            .Read(read => read.Action("GetJobs", "Grid").Data("passFilter"))
            .Create(create => create.Action("JobAllocation_Create", "JOBS"))
            .Update(create => create.Action("JobAllocation_Update", "JOBS"))
            .Destroy(create => create.Action("JobAllocation_Destroy", "JOBS"))
        )
    )

     

     Dropdownlist template

    @using ServicePROWeb.Models;
     
    @{
        DropDownListItem ddp;
        List<DropDownListItem> list = new List<DropDownListItem>();
     
        foreach(var scheduleCheckBox in (List<ScheduleCheckBox>)Session["TreatmentCheckBoxes"])
        {
            ddp = new DropDownListItem();
            ddp.Text = scheduleCheckBox.Status;
            ddp.Value = scheduleCheckBox.Status;
            list.Add(ddp);
        }
    }
     
    @(Html.Kendo().DropDownList()
        .Name("statusDropDownList")
        .DataTextField("Text")
        .DataValueField("Value")
        .SelectedIndex(4)
        .BindTo(list)
        .Events(e => e.Select("statusDropDownList_onSelect").DataBound("statusDropDownList_onDataBound").Open("statusDropDownList_onOpen"))
    )

     

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 17 Nov 2015 Link to this post

    I have already tried to follow the demo sample code but it didn't help me.
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Nov 2015 Link to this post

    Hello Kevork,

     

    Please refer to the Editor Templates article that shows how to define a custom editor for a specific column. 
     
    What I can notice in the provided example is that the Name of the DropDownList widget is not the same as the model field name. As explained in the third point "Set the Name of the DropDownList to the name of the property which will be edited". 
     
    Also an option is to avoid defining a Name and use the DropDownListFor view helper. It takes automatically the model field name and configure the id value of the element and bindings. Actually I would suggest this approach. 

     

     

    Regards,
    Boyan Dimitrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 24 Nov 2015 in reply to Boyan Dimitrov Link to this post

    Thanks for the reply.

    I changed the name of the dropdownlist as the model field name. It  worked but not fully. I have still some issues. When I click on the "ST" column, it shows the dropdownlist with value but wrong value. It should show "DC" but showing the first value of the dropdownlist, "DB". And another problem is when I click for the second time on the "ST" column of another row, it shows textbox instead of dropdownlist.

    @using ServicePROWeb.Models;
     
    @(Html.Kendo().DropDownList()
        .Name("gr_status")
        .DataTextField("Status")
        .DataValueField("Id")   
        .BindTo((List<ScheduleCheckBox>)Session["TreatmentCheckBoxes"])
        .Events(e => e.Select("statusDropDownList_onSelect").DataBound("statusDropDownList_onDataBound").Open("statusDropDownList_onOpen"))
    )

     

    I have attached the images to clarify.

     

     Thanks

  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 26 Nov 2015 Link to this post

    Hello Kevork,

     

    Could you please send us an isolated runnable example in order to investigate this problem? Since I am aware of such problem I would need to review and test the specific case. 

     

    Regards,
    Boyan Dimitrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 01 Dec 2015 in reply to Boyan Dimitrov Link to this post

    Here is the runnable project. I have used VS 2015.

    When I click on the ST column of the grid, the dropdown becomes visible but item doesn't show. I have to click again to select value from dropdownlist. The selected item should be shown when I click first time.

     

     Thanks.

  9. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 01 Dec 2015 in reply to Boyan Dimitrov Link to this post

    Here is the runnable project. I have used VS 2015. I couldn't attach runnable project because of file size restriction. You need to attach all Kendo scripts, dll and css.

    When I click on the "ST" column of the grid, the dropdownlist appears but shows no value selected. The dropdownlist needs to be clicked again and then the item can be selected. But I need the dropdownlist to be appeared with the selected value and in expanded mode.

    In the project, when I click on the ST column, the dropdownlist should appear with value "DC" and expanded with other values.

     Thanks


  10. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 01 Dec 2015 in reply to Boyan Dimitrov Link to this post

    Please ignore the previous attached project. Use this one.

     

    Thanks

  11. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 03 Dec 2015 Link to this post

    Hello Kevork,

    By default the value binding for the select widgets(AutoComplete, DropDownList, ComboBox, MultiSelect) uses the value of the selected item to update the View-Model field. So in this case the value of the "Status" field is "DC" and it looks for an item with value "DC", but the values are numbers and there is no item with value "DC". 

    A possible solution is either to have same text and value for the DropDownList widget: 

    @using ServicePROWeb.Models;
     
    @(Html.Kendo().DropDownList()
        .Name("Status")
        .DataTextField("Text")
        .DataValueField("Value")
        .SelectedIndex(1)
        .BindTo(new List<SelectListItem>() {
                new SelectListItem() {
                    Text = "DB",
                    Value = "DB"
                },
                new SelectListItem() {
                    Text = "DC",
                    Value = "DC"
                },
                new SelectListItem() {
                    Text = "DA",
                    Value = "DA"
                }
            }
        )
    )

    or use the ForeignKey column approach. Please refer to the Grid / ForeignKey column demo. 

     

    Regards,
    Boyan Dimitrov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  12. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 06 Dec 2015 in reply to Boyan Dimitrov Link to this post

    Thanks for the suggestion. I'll try and let you know.
  13. Kevork
    Kevork avatar
    39 posts
    Member since:
    May 2015

    Posted 14 Jan in reply to Boyan Dimitrov Link to this post

    Hi,

    This thread (ForeignKey) solved my problem. The attached project helped me to solve my issue.

     

    Thanks

Back to Top
UI for ASP.NET MVC is VS 2017 Ready