开发者

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

开发者 https://www.devze.com 2023-02-15 03:22 出处:网络
SelectList tempList = Chatham.Web.Models.Shared.DropDownData.IndicationsGroup( SessionManager.Company.EntityID,
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

精彩评论

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