Reputation: 2760
string EmailDomain = useremail.Split('@')[1].Trim();
foreach (ListItem li in lst_DomainList.Items)
{
if (EmailDomain.Equals(li))
{
}
}
If the input is [email protected]
then after split the EmailDomain value is email.com
the value inside the list are
email
email.com
Here the second items in the list matches with the EmailDomain value,. but the way I have done it it says they dont match, what should I do
Upvotes: 2
Views: 1037
Reputation: 1247
ListItem li
refers to the actual item in the list box. You should compare against li.Text
Upvotes: 1
Reputation: 1500795
You're comparing the string with the ListItem
itself. You probably want to compare with li.Value
or li.Text
...
string domain = userEmail.Split('@')[1].Trim();
foreach (ListItem li in lst_DomainList.Items)
{
if (li.Value == domain)
{
...
}
}
Upvotes: 4