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

SelectedValue not changed when fill Text in code

1 Answer 62 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 22 Feb 2019, 09:37 AM

After bind the DropdownList with datatable, I set the Text of the DropdownList in code, if the Text match one of element of the datatable, the SelectedValue should changed at the same time, in my case, it is not, I need to click the DropdownList to change the SelectedValue. 

Anything I can do to sync the action that I get the right SelectedValue  when I set Text match one of element of the datatable?

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Feb 2019, 11:59 AM
Hi Ricardo,

This should work, please make sure that you are setting the text after the control is already loaded and the data source is set. 

Another approach is to directly set the selected value: 
public RadForm1()
{
    InitializeComponent();
    radDropDownList1.ValueMember = "Name";
    radDropDownList1.DisplayMember = "Name";
    radDropDownList1.DataSource = GetTable();
}
private void RadButton1_Click(object sender, EventArgs e)
{
    radDropDownList1.SelectedValue = "Sam";
}

I hope this helps.  

Regards,
Dimitar
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DropDownList
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or