Completed
Last Updated: 17 Sep 2020 10:55 by ADMIN
Release 2.18.0
Conie
Created on: 22 Mar 2020 08:46
Category: DropDownList
Type: Bug Report
4
Dropdown box does not update the Text of the currently selected item after the bound data has been updated.
I have logic that updates the Data of a dropdownlist (in this case, changes the value of the TextField of a the selected item in the dropdown). After the database update, I fetch the dropdown data anew, and it reflects in the dropdown element, but not in the main element where it is currently shown.
4 comments
Shashishekar
Posted on: 09 Jun 2020 17:21

Thank you Marin. As suggested by you, we have implemented this workaround and working fine.

Also It would be really helpful if this is fixed in subsequent releases.

Jagannath
Posted on: 09 Jun 2020 16:42
Thank you, This workaround worked for me as well. I have voted for this. It would be really helpful if you fix this bug.
Conie
Posted on: 23 Mar 2020 18:39
Thank you, your response got it working for me.
ADMIN
Marin Bratanov
Posted on: 22 Mar 2020 08:54

Here is a reproducible and a workaround (highlighted in green):

<p>repro: select "item 4", click the button. Expected: the text in the DDL changes. Actual: only the text in the dropdown changes</p>

@OriginAgentID

<TelerikButton OnClick="@ChangeItem">Change item 4</TelerikButton>

<TelerikDropDownList Class="dropdown-combo-small " Width="230px" OnChange="OriginAgentChange"
                     PopupHeight="auto" Data="@OriginAgentList" TextField="CompanyName" ValueField="AgentID"
                     @bind-Value="@OriginAgentID" DefaultText="Select">
</TelerikDropDownList>

@code {
    protected override async Task OnInitializedAsync()
    {
        OriginAgentList = Enumerable.Range(1, 10).Select(x => new MyDdlModel { CompanyName = "item " + x, AgentID = x }).ToList();
    }

    async Task ChangeItem()
    {
        await Task.Delay(500);//simulate database wait
        //change data
        OriginAgentList[3].CompanyName = "changed at " + DateTime.Now.Millisecond;

        //create a new reference so the OnParametersSet of the component fires and it can know there is new data
        OriginAgentList = new List<MyDdlModel>(OriginAgentList);

        int currSelectedItem = OriginAgentID;
        OriginAgentID = 0;
        StateHasChanged();
        //add this if it does not work
        //await Task.Delay(30);//wait a rendering frame
        OriginAgentID = currSelectedItem;
        //add this if it does not work
        //StateHasChanged();
    }

    void OriginAgentChange(object theUserInput)
    {
        Console.WriteLine(theUserInput);
        string result = string.Format("The user selected: {0}", (int)theUserInput);
    }

    public class MyDdlModel
    {
        public int AgentID { get; set; }
        public string CompanyName { get; set; }
    }

    List<MyDdlModel> OriginAgentList { get; set; }

    int OriginAgentID { get; set; }
}

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor