Return to Snippet

Revision: 10724
at January 11, 2009 05:53 by naspinski


Initial Code
public static void Set(this DropDownList ddl, string findByVal)
{ // attempts to set a DDL to the 'findByVal'
  try { ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(findByVal)); }
  catch { }; // otherwise statys at the default, avoids errors
}

Initial URL
http://naspinski.net/post/Simplify-setting-your-DropDownLists-to-a-specific-value.aspx

Initial Description
usage:
SomeDropDownList.Set("Some String Value");

Initial Title
set your DropDownList to a specified value

Initial Tags
c, aspnet

Initial Language
ASP