User-893317190 posted
Hi TechView,
It seems that you want when item2.Text == item.roleName, make the listitem selected.
What's the valuefield of your dropdownlist ?Is it your roleName?
If so,please use ddlUserRole.SelectedValue property instead of SelectedItem property.
For example , If your dropdown has two listitem {"role1":"role1value" , "role2":"role2value"} and its selecteditem is role1.
When you use this way to select role2 ,ddlUserRole.SelectedItem.Value="role2value",it will be {"role1":"role2value" ,"role2":"role2value"}.
It just changes the value of the selectedItem instead of change the selected item.
If you want to use loop , you could try
if (item2.Text == item.roleName) //If role matches
{
item2.selected = true; //Get the selected role name by default while editing user details
}
Best regards,
Ackerly Xu