Exemplo n.º 1
0
        private SelectListGroup GetGroup(object container)
        {
            if (_groups == null)
            {
                return(null);
            }

            var groupName = Eval(container, DataGroupField);

            if (string.IsNullOrEmpty(groupName))
            {
                return(null);
            }

            // We use StringComparison.CurrentCulture because the group name is used to display as the value of
            // optgroup HTML tag's label attribute.
            var group = _groups.FirstOrDefault(g => string.Equals(g.Name, groupName, StringComparison.CurrentCulture));

            if (group == null)
            {
                group = new SelectListGroup()
                {
                    Name = groupName
                };
                _groups.Add(group);
            }

            return(group);
        }
Exemplo n.º 2
0
        private SelectListGroup GetGroup(object container)
        {
            if (_groups == null)
            {
                return(null);
            }

            var groupName = Eval(container, DataGroupField);

            if (string.IsNullOrEmpty(groupName))
            {
                return(null);
            }

            // We use StringComparison.CurrentCulture because the group name is used to display as the value of
            // optgroup HTML tag's label attribute.
            SelectListGroup group = null;

            for (var index = 0; index < _groups.Count; index++)
            {
                if (string.Equals(_groups[index].Name, groupName, StringComparison.CurrentCulture))
                {
                    group = _groups[index];
                    break;
                }
            }

            if (group == null)
            {
                group = new SelectListGroup()
                {
                    Name = groupName
                };
                _groups.Add(group);
            }

            return(group);
        }