开发者

Check if text appears on the text property of any element in SelectList

SelectList tempList =
    Chatham.Web.Models.Shared.DropDownData.IndicationsGroup(
        SessionManager.Company.EntityID,
        ICConstants.IndicationsCalculatorGroupType);

foreach (SelectListItem item in tempList)
{
    if (value.ToString() == item.Value)
    {
        if (item.Text == "Create a New Group")
        {
            GroupDisplayName = "";
            break;
        }
        GroupDisplayName = item.Text;
        break;
    }
}

On the line where it clears the previously set value: GroupDisplayName = "";, I instead want it to check what that previously set text was, and if that text IS IN one of the text properties of the items in tempList, that's the only time it should clear it.

Edit:

I know I could do this by looping through every element, but I am already with开发者_运维知识库in a loop of the same exact type, so I would not want to increase complexity this much. I was hoping there was some sort on LINQ query or something I could use, or something along the lines of that.


if (tempList.Select(i => i.Text).Contains(GroupDisplayName))
     // do the rest
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜