Pages

Dec 23, 2008

How to select an item in a DropDownList by Value


1. //How to select an item in a DropDownList by Value

ListItem li = yourDropDownlist.Items.FindByValue(”yourValue”);

if (li != null)

yourDropDownlist.SelectedIndex = yourDropDownlist.Items.IndexOf(li);

2. //How to check if value exists in DropDownList

public static bool IsValueInDropdownList(DropDownList controlName,string strValue)

{

if (controlName.Items.FindByValue(strValue) != null)

return true;

else
return false;

}

No comments: