Posted By

naspinski on 01/11/09


Tagged

c aspnet DropDownList


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

benrudolph


set your DropDownList to a specified value


 / Published in: ASP
 

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

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

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

Report this snippet  

You need to login to post a comment.