ASP.NET - dropCity.Items.FindByText(City).Selected = true;

Asked By msakt on 21-Jun-12 12:35 AM
string city ="MISSION VIJEO";
but dropdown value have Mission Vijeo....
because case sensitive...
dropCity.Items.FindByText(City).Selected = true;
Jitendra Faye replied to msakt on 21-Jun-12 12:49 AM
Change your code like this-

      string city ="MISSION VIJEO";
      DropDownList1.Items.FindByText(city.ToLower ()).Selected = true;

Try this and let me know.
TSN ... replied to msakt on 21-Jun-12 01:05 AM


Below is the a small helper method which you can this for incasesentivity of Dropdownlist findByText

public ListItem FindByTextCaseInsensitive(ListControl  ddlctl, string text)


          if (ddlctl == null)

                  return null;

          foreach (ListItem li in ddlctl.Items) {

                  if (string.Compare(li.Text, text, true) == 0)

                          return li;


          return null;




just use this method instead of already defined method FindByText.

dropCity.SelectedItem= FindByTextCaseInsensitive(dropCity, City);