Telerik Combobox loses it's binding grid when pressed update

1 Answer 19 Views
ComboBox Grid
ASIM
Top achievements
Rank 1
ASIM asked on 29 Apr 2021, 03:35 PM | edited on 29 Apr 2021, 03:37 PM

Hello,

I want to use a combobox in a telerik grid,  I'm succesfully able to bind and display the data in the combobox as well. 

however when I select a value from the combobox and press the update button,  I get out of the edit mode and the combobox 

value goes back to null. (placeholder)

 

here is a simplified version of my models


  public class PageControlsM
    {

        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        public string ControlCode { get; set; }

        [ForeignKey("ControlCode")]
        public  ControlTypes ControlTypes { get; set; }

    }

 

public class ControlTypes
    {
        [Key]
        public string Code { get; set; }
        
        public string ControlName { get; set; }

        public string HtmlCode { get; set; }
    }

 

and this is my grid implementation:


 <TelerikGrid Data="@PageControlList"
                  Height="auto"
                  Pageable="true"
                  Sortable="true"
                  Reorderable="true"
                  Resizable="true"
                  PageSize="5"
                  EditMode="GridEditMode.Popup">
            <GridToolBar>
                <GridCommandButton Command="Add" Icon="add">Yeni Kontrol Ekle</GridCommandButton>
            </GridToolBar>
            <GridColumns>

                <GridColumn Field=@nameof(PageControlsM.ControlCode) Width="100%" Title="Kontrol Turu">
                    <EditorTemplate Context="controlMContext">
                        @{
                                if (controlMContext is PageControlsM controlM)
                                {
                                <TelerikComboBox Data="@ControlTypesList"
                                                 TextField="ControlName"
                                                 ValueField="Code"
                                                 Width="90%"                                                
                                                 @bind-Value="controlM.ControlCode"
                                                 Placeholder="<Seciniz>"
                                                 ClearButton="true"
                                                 Filterable="false">
                                </TelerikComboBox>
                                }
                        }
                    </EditorTemplate>

                </GridColumn>

                <GridCommandColumn Width="100%">

                    <GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton>
                    <GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
                    <GridCommandButton Command="Update" Icon="update" ShowInEdit="true">Update</GridCommandButton>

                    <GridCommandButton Command="Save" Icon="cancel" ShowInEdit="true">Save</GridCommandButton>
                    <GridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</GridCommandButton>
                </GridCommandColumn>

            </GridColumns>

        </TelerikGrid>

 

 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 30 Apr 2021, 10:58 AM

Hi Asim,

Please try storing the reference to the currently edited row in a field in the view-model like shown in the documentation: https://docs.telerik.com/blazor-ui/components/grid/templates/editor.

The current code will create a new reference every time the editor template re-renders, and that can happen many times for many reasons, and can thus affect the code in the editor template.

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ComboBox Grid
Asked by
ASIM
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or