Esempio n. 1
0
        /// <summary>
        /// 将DataSource转换成指定的Items
        /// </summary>
        /// <param name="listItem"></param>
        protected void PerformanceData(MultiListBoxItem listItem)
        {
            object dataSource = listItem.DataSource;

            if (dataSource != null)
            {
                bool flag_display = false;
                bool flag_format  = false;

                string propName       = this.DataTextField;
                string dataValueField = this.DataValueField;
                string format         = this.DataTextFormatString;

                ICollection data = dataSource as ICollection;
                if (data != null)
                {
                    listItem.Items.Capacity = listItem.Items.Count + data.Count;
                }
                if (propName.Length != 0 || dataValueField.Length != 0)
                {
                    flag_display = true;
                }
                if (this.DataTextFormatString.Length != 0)
                {
                    flag_format = true;
                }
                foreach (object obj in data)
                {
                    ListItem item = new ListItem();
                    //自定义显示TextField,ValueField
                    if (flag_display)
                    {
                        if (propName.Length > 0)
                        {
                            item.Text = DataBinder.GetPropertyValue(obj, propName).ToString();
                        }
                        if (dataValueField.Length > 0)
                        {
                            item.Value = DataBinder.GetPropertyValue(obj, dataValueField).ToString();
                        }
                    }
                    else
                    {
                        if (flag_format)
                        {
                            item.Text = string.Format(CultureInfo.CurrentCulture, format, new object[] { obj });
                        }
                        else
                        {
                            item.Text = obj.ToString();
                        }
                    }
                    listItem.Items.Add(item);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="multiListItem"></param>
        /// <param name="name"></param>
        /// <param name="jsDbClick"></param>
        protected void RenderOptionsContents(HtmlTextWriter writer, MultiListBoxItem multiListItem, string name, string jsDbClick)
        {
            ListItemCollection items = multiListItem.Items;

            writer.AddAttribute("name", this.ClientID + "_" + name);
            writer.AddAttribute("id", this.ClientID + "_" + name);
            writer.AddAttribute("size", this.Rows.ToString());
            writer.AddAttribute("onDblClick", jsDbClick);

            if (SelectionMode == ListSelectionMode.Multiple)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Multiple, "multiple");
            }

            //输出CSS定义
            if (multiListItem.StyleSheet != null)
            {
                StringBuilder sb         = new StringBuilder();
                string        sheetValue = multiListItem.StyleSheet.Width;
                if (sheetValue != null && sheetValue != "")
                {
                    sb.AppendFormat("width:{0};", sheetValue);
                }
                sheetValue = multiListItem.StyleSheet.Height;
                if (sheetValue != null && sheetValue != "")
                {
                    sb.AppendFormat("height:{0};", sheetValue);
                }
                writer.AddAttribute("style", sb.ToString());
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Select);

            int count = items.Count;

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    ListItem item = items[i];
                    writer.AddAttribute("value", item.Value, true);
                    writer.RenderBeginTag(HtmlTextWriterTag.Option);
                    writer.Write(item.Text);
                    writer.RenderEndTag();
                }
            }
            writer.RenderEndTag();
        }
Esempio n. 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="multiListItem"></param>
 /// <param name="name"></param>
 /// <param name="jsDbClick"></param>
 protected void RenderOptionsContents(HtmlTextWriter writer, MultiListBoxItem multiListItem, string name, string jsDbClick)
 {
     ListItemCollection items = multiListItem.Items;
     writer.AddAttribute("name", this.ClientID + "_" + name);
     writer.AddAttribute("id", this.ClientID + "_" + name);
     writer.AddAttribute("size", this.Rows.ToString());
     writer.AddAttribute("onDblClick", jsDbClick);
     if (SelectionMode == ListSelectionMode.Multiple)
         writer.AddAttribute(HtmlTextWriterAttribute.Multiple, "multiple");
     //输出CSS定义
     if (multiListItem.StyleSheet != null)
     {
         StringBuilder sb = new StringBuilder();
         string sheetValue = multiListItem.StyleSheet.Width;
         if (sheetValue != null && sheetValue != "")
             sb.AppendFormat("width:{0};", sheetValue);
         sheetValue = multiListItem.StyleSheet.Height;
         if (sheetValue != null && sheetValue != "")
             sb.AppendFormat("height:{0};", sheetValue);
         writer.AddAttribute("style", sb.ToString());
     }
     writer.RenderBeginTag(HtmlTextWriterTag.Select);
     int count = items.Count;
     if (count > 0)
     {
         for (int i = 0; i < count; i++)
         {
             ListItem item = items[i];
             writer.AddAttribute("value", item.Value, true);
             writer.RenderBeginTag(HtmlTextWriterTag.Option);
             writer.Write(item.Text);
             writer.RenderEndTag();
         }
     }
     writer.RenderEndTag();
 }
Esempio n. 4
0
        /// <summary>
        /// 将DataSource转换成指定的Items
        /// </summary>
        /// <param name="listItem"></param>
        protected void PerformanceData(MultiListBoxItem listItem)
        {
            object dataSource = listItem.DataSource;
            if (dataSource != null)
            {
                bool flag_display = false;
                bool flag_format = false;

                string propName = this.DataTextField;
                string dataValueField = this.DataValueField;
                string format = this.DataTextFormatString;

                ICollection data = dataSource as ICollection;
                if (data != null)
                {
                    listItem.Items.Capacity = listItem.Items.Count + data.Count;
                }
                if (propName.Length != 0 || dataValueField.Length != 0)
                    flag_display = true;
                if (this.DataTextFormatString.Length != 0)
                    flag_format = true;
                foreach (object obj in data)
                {
                    ListItem item = new ListItem();
                    //自定义显示TextField,ValueField
                    if (flag_display)
                    {
                        if (propName.Length > 0)
                        {
                            item.Text = DataBinder.GetPropertyValue(obj, propName).ToString();
                        }
                        if (dataValueField.Length > 0)
                        {
                            item.Value = DataBinder.GetPropertyValue(obj, dataValueField).ToString();
                        }
                    }
                    else
                    {
                        if (flag_format)
                        {
                            item.Text = string.Format(CultureInfo.CurrentCulture, format, new object[] { obj });
                        }
                        else
                        {
                            item.Text = obj.ToString();
                        }
                    }
                    listItem.Items.Add(item);
                }
            }
        }