G
Guest
I need to set the selected drop down list value at run time. I am aware of
the method "SelectIndex" however this works only if you know the precise
location of the value within the ListItem collection. Otherwise, what is the
recommended approach?
I have managed to set the appropriate value using the following loop:
for (int i = 1; i < ddlUsers.Items.Count; i++)
{
if (ddlUsers.Items.ToString() == sUserId)
{
ddlUsers.SelectedIndex = i;
break;
}
}
However, I wonder if there's an easier way than this "home-made" solution?
Thanks.
the method "SelectIndex" however this works only if you know the precise
location of the value within the ListItem collection. Otherwise, what is the
recommended approach?
I have managed to set the appropriate value using the following loop:
for (int i = 1; i < ddlUsers.Items.Count; i++)
{
if (ddlUsers.Items.ToString() == sUserId)
{
ddlUsers.SelectedIndex = i;
break;
}
}
However, I wonder if there's an easier way than this "home-made" solution?
Thanks.