Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
YAQ on DropDownList
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01119321
Message ID:
01119338
Vues:
17
>>I am having a problem where code does not find an item in a DropDownList (DDL):
>>
>>If I scan items in the drop down list as following:
>>
>>
>>for (int i =0;i < ddlSite.Items.Count ;i++ )
>>{		
>>  Response.Write( ddlSite.Items[i].Value.ToString() );
>>}
>>
>>
>>I can clearly see the item.
>>
>>But if I check for My item in code, nothing found. Here is an example:
>>
>>
>>string MyString = "ABC";
>>for (int i =0;i < ddlSite.Items.Count ;i++ )
>>{
>>  if ( ddlSite.Items[i].Value.ToString().Equals(MyString))
>>  {
>>     Response.Write("Bingo!" );
>>  }							
>>}
>>
>>
>>or if I do the following:
>>
>>ListItem selectedItem = ddlSite.Items.FindByValue( MyString );
>>// here selectedItem is NULL
>>
>>
>>I never get Bingo. And as I mentioned, the DDL does have an item with value "ABC". What am I missing?
>
>Dmitry;
>
>Does this work for you?
>
>
>ddlSite.SelectedIndex = ddlSite.Items.IndexOf(ddlSite.Items.FindByValue(MyString));
>
>

Tom,

No. The .SelectedIndex returns 0. This is the problem, the method .FindByValue does not find the string.

Thank you for your suggestion.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform