示例#1
0
        public static string AddDropDownList(StringBuilder sb, string key, string id, long?value, long?valueNotSet, string textNotSet, IDataSource dataSource, string width)
        {
            var         idValue        = key + "_" + id;
            var         view           = dataSource.GetView("default");
            IEnumerable dataSourceData = null;

            view.Select(new DataSourceSelectArguments(), delegate(IEnumerable data) { dataSourceData = data; });
            if (dataSourceData != null)
            {
                sb.AppendFormat(HtmlGenerator.dropDownListStart, idValue, width, HtmlGenerator.dropDownListScript);
                sb.AppendFormat(
                    valueNotSet == value ? HtmlGenerator.dropDownListSelectedOption : HtmlGenerator.dropDownListOption,
                    valueNotSet, textNotSet);
                foreach (var row in dataSourceData)
                {
                    var propertyID   = row.GetType().GetProperty("id");
                    var propertyName = row.GetType().GetProperty(FindHelper.GetContentFieldName("nameRu", "nameKz"));
                    var rowID        = (long)propertyID.GetValue(row, null);
                    var rowName      = propertyName.GetValue(row, null);
                    sb.AppendFormat(
                        rowID == value ? HtmlGenerator.dropDownListSelectedOption : HtmlGenerator.dropDownListOption,
                        rowID, rowName);
                }
                sb.AppendFormat(HtmlGenerator.dropDownListEnd);
            }
            return(idValue);
        }
            /// <summary>
            /// Заполнить спсок DataSourceOther.
            /// </summary>
            public void FillDataSourceOther(int maximumRows)
            {
                var            list     = new List <KeyValuePair <long, string> >();
                DataSourceView view     = DataSource.GetView("default");
                var            baseView = view as BaseDataSourceView <long>;

                if (baseView != null)
                {
                    baseView.CancelTreeUse = true;
                }
                IEnumerable dataSourceData = null;
                var         arguments      = new DataSourceSelectArguments();

                if (maximumRows > 0)
                {
                    arguments.MaximumRows = maximumRows;
                }

                view.Select(arguments, delegate(IEnumerable data) { dataSourceData = data; });
                if (dataSourceData != null)
                {
                    var          enumerator   = dataSourceData.GetEnumerator();
                    PropertyInfo propertyID   = null;
                    PropertyInfo propertyName = null;
                    if (enumerator.MoveNext())
                    {
                        var fieldName = FindHelper.GetContentFieldName("nameRu", "nameKz");
                        var row       = enumerator.Current;
                        propertyID   = row.GetType().GetProperty("id");
                        propertyName = row.GetType().GetProperty(fieldName);
                        list.Add(
                            new KeyValuePair <long, string>(
                                (long)propertyID.GetValue(row, null),
                                (propertyName.GetValue(row, null) ?? string.Empty).ToString()));
                    }

                    while (enumerator.MoveNext())
                    {
                        var row = enumerator.Current;
                        list.Add(
                            new KeyValuePair <long, string>(
                                (long)propertyID.GetValue(row, null),
                                (propertyName.GetValue(row, null) ?? string.Empty).ToString()));
                    }
                }

                DataSourceOther = list;
            }