In a static class:
public static void SelectItemByValue(this DropDownList dropDownList, Nullable value) where T : struct
{
if (value.HasValue)
{
ListItem listItem = dropDownList.Items.FindByValue(value.Value.ToString());
if (listItem != null)
{
listItem.Selected = true;
return;
}
}
if (dropDownList.Items.Count > 0)
{
dropDownList.Items[0].Selected = true;
return;
}
}
No comments:
Post a Comment