Domanda

I am using this filter in my AutoCompeteBox.

bool SearchBird(string search, object value)
        {
            if (value != null)
            {
                AllBirds datasourceValue = value as AllBirds;
                string name = datasourceValue.primary_language;

                if (name.ToLower().StartsWith(search.ToLower()))
                return true;

            }
            // If no match, return false. 
            return false;
        } 

Everything is working well when all entries have some value, but when there is any empty record it's crushing giving an error with null exception (which is understandable as there is no value). Tried do smth with extra if or else statement but still getting the same error.

È stato utile?

Soluzione

more better if u use if else?

add this after if, may be help

else {
 return false;
}

Altri suggerimenti

I've done that like that.

if (value != null)
            {
                AllBirds datasourceValue = value as AllBirds;
                string name = datasourceValue.primary_language;

                if (name == null)
                    return false;

                if (name.ToLower().StartsWith(search.ToLower()))
                return true;

            }
            // If no match, return false. 
            return false;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top