Esempio n. 1
0
 // This function binds the given RadioButtonList with the given data table with respect to the data text field and the value field.
 public static void Bind2RadioButtonList(ListControl rbl, DataTable dt, string textField, string valueField)
 {
     rbl.DataSource = dt;
     rbl.DataTextField = textField;
     rbl.DataValueField = valueField;
     rbl.DataBind();
 }
Esempio n. 2
0
 public static void Fillchk(ListControl control, string key, string value, object data)
 {
     control.DataSource = data;
     control.DataValueField = key;
     control.DataTextField = value;
     control.DataBind();
 }
Esempio n. 3
0
        private static void AssemblingMyList(System.Web.UI.WebControls.ListControl myListControl, object myList, string ValueField, string TextField)
        {
            try
            {
                // List<List2Item> myList = myList;
                myListControl.Items.Clear();
                myListControl.DataSource     = myList;
                myListControl.DataTextField  = TextField;
                myListControl.DataValueField = ValueField;
                myListControl.DataBind();
                myListControl.SelectedIndex = 0;

                if (myListControl.Items.Count > 1)
                {
                    myListControl.Enabled = true;
                }
                else
                {
                    myListControl.Enabled = false;
                }
            }
            catch (Exception ex)
            { var em = ex.Message; }
            finally
            { }
        }
Esempio n. 4
0
 public static void Bind2Ddl(ListControl ddl, DataTable dt, string textField, string valueField)
 {
     ddl.DataSource = dt;
     ddl.DataTextField = textField;
     ddl.DataValueField = valueField;
     ddl.DataBind();
 }
Esempio n. 5
0
 public static void FillRange(ListControl control, int min = 1, int max = 10)
 {
     control.DataSource = GetRange(min, max);
     control.DataValueField = "key";
     control.DataTextField = "value";
     control.DataBind();
 }
Esempio n. 6
0
 // This function binds the given CheckBoxList with the given data table with respect to the data text field and the value field.
 public static void Bind2CheckBoxList(ListControl chk, DataTable dt, string textField, string valueField)
 {
     chk.DataSource = dt;
     chk.DataTextField = textField;
     chk.DataValueField = valueField;
     chk.DataBind();
 }
Esempio n. 7
0
 public static void BindObject(ListControl ddl, DataTable data, string textColumn, string valueConlumn, string defaultText)
 {
     ddl.DataSource = data;
     ddl.DataTextField = textColumn;
     ddl.DataValueField = valueConlumn;
     ddl.DataBind();
     ddl.Items.Insert(0, new ListItem(defaultText, "-1"));
 }
Esempio n. 8
0
        private static Dictionary<string, Dictionary<int, string>> _EnumList = new Dictionary<string, Dictionary<int, string>>(); //枚举缓存池

        #endregion Fields

        #region Methods

        /// <summary>
        /// bind source for ListControl;ex:DropDown,ListBox;
        /// </summary>
        /// <param name="listControl"></param>
        /// <param name="enumType"></param>
        public static void BindListControl(ListControl listControl, Type enumType)
        {
            listControl.Items.Clear();
            listControl.DataSource = EnumToDictionary(enumType);
            listControl.DataValueField = "key";
            listControl.DataTextField = "value";
            listControl.DataBind();
        }
Esempio n. 9
0
 /// <summary>
 /// 邦定DorpDownList
 /// </summary>
 /// <param name="DataScore">数据源</param>
 /// <param name="DL">DropdownList控件</param>
 /// <param name="DataTextField">Item文本</param>
 /// <param name="DataValueField">Item值</param>
 public virtual void BindDoprdownList(object DataScore, System.Web.UI.WebControls.ListControl DL, string DataTextField, string DataValueField)
 {
     DL.DataSource     = DataScore;
     DL.DataTextField  = DataTextField;
     DL.DataValueField = DataValueField;
     DL.DataBind();
     DL.Dispose();
 }
Esempio n. 10
0
        public static void BindToEnum(Type enumType, ListControl lc, bool addEmpty)
        {
            Dictionary<string, string> ht = EnumToDictionary(enumType, addEmpty);

            lc.DataSource = ht.OrderBy(x => x.Key);
            lc.DataTextField = "Key";
            lc.DataValueField = "Value";
            lc.DataBind();
        }
Esempio n. 11
0
        public static void FillCollection(ListControl control, string key, string value, object data, bool isAddSelect = true)
        {
            control.DataSource = data;
            control.DataValueField = key;
            control.DataTextField = value;
            control.DataBind();

            if (isAddSelect)
                control.Items.Insert(0, new ListItem("--- Select ---", "0"));
        }
Esempio n. 12
0
    //打开一个OracleClient类型的数据库连接,返回一个OracleCommand,用于执行对CLOB的特殊处理

    /*  public OracleCommand OpenOracleCommand()
     * {
     *    //建立Oracle类型的数据库连接
     *    string connStr = System.Configuration.ConfigurationSettings.AppSettings["OraCLientConnStr"];
     *    OracleConnection connOraClient = new OracleConnection(connStr);
     *
     *    //建立OracleCommand,并设置其相关属性
     *    OracleCommand dbCmd = new OracleCommand();
     *    dbCmd.Connection = connOraClient;
     *    dbCmd.CommandType = CommandType.Text;
     *    try
     *    {
     *        connOraClient.Open();
     *    }
     *    catch
     *    {
     *        return null;
     *    }
     *    finally
     *    {
     *        //connOraClient.Close();
     *    }
     *    return dbCmd;
     * }
     *
     */
    //根据SQL语句建立OracleDataReader,以完成对LOB的读取

    /*   public OracleDataReader OraDataReader(string sql)
     * {
     *     OracleDataReader Odr = null;
     *     try
     *     {
     *         OracleCommand dbCmd = OpenOracleCommand();
     *         dbCmd.CommandText = sql;
     *         Odr = dbCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
     *     }
     *     catch
     *     {
     *         try
     *         {
     *             if (Odr != null && !Odr.IsClosed)
     *                 Odr.Close();
     *         }
     *         catch
     *         {
     *             return null;
     *         }
     *         finally
     *         {
     *             closeConnection();
     *         }
     *     }
     *     return Odr;
     * }
     */

    //把一个下拉列表框绑定到数据库中的一个表
    public void BindWebListCtrl(System.Web.UI.WebControls.ListControl webCtrl, string table)
    {
        string    sql = "select id,name from " + table + " order by id";
        DataTable dt  = new DataTable();

        dt = dataTable(sql);
        webCtrl.DataSource     = dt;
        webCtrl.DataValueField = dt.Columns[0].ToString();
        webCtrl.DataTextField  = dt.Columns[1].ToString();
        webCtrl.DataBind();
    }
 /// <summary>
 /// 列表类型控件数据绑定。
 /// </summary>
 /// <param name="control">列表类型控件(BulletedList,CheckBoxList,DropDownList,ListBox,RadioButtonList)。</param>
 /// <param name="listControlsDataSource">数据源接口。</param>
 public void ListControlsDataSourceBind(ListControl control, IListControlsData listControlsDataSource)
 {
     if (control != null && listControlsDataSource != null)
     {
         control.DataTextField = listControlsDataSource.DataTextField;
         if (!string.IsNullOrEmpty(listControlsDataSource.DataTextFormatString))
             control.DataTextFormatString = listControlsDataSource.DataTextFormatString;
         control.DataValueField = listControlsDataSource.DataValueField;
         control.DataSource = listControlsDataSource.DataSource;
         control.DataBind();
     }
 }
        public static void BindDictionaryToListControl(ListControl list, string categoryName)
        {
            list.DataSource = SystemDictionaryWrapper.GetDictionaryByCategoryName(categoryName);
            list.DataTextField = SystemDictionaryWrapper.PROPERTY_NAME_SYSTEMDICTIONARYVALUE;
            list.DataValueField = SystemDictionaryWrapper.PROPERTY_NAME_SYSTEMDICTIONARYKEY;
            list.DataBind();

            if (list.Items.Count > 0)
            {
                list.SelectedIndex = 0;
            }
        }
Esempio n. 15
0
 public static void FillList(ListControl ctrl, DataTable dataSource, string DataTextField, string DataValueField, bool UseOthersOption = true, string OthersLabel = "Select", string othersValue = "-1")
 {
     ctrl.Items.Clear();
     ctrl.DataTextField = DataTextField;
     ctrl.DataValueField = DataValueField;
     ctrl.DataSource = dataSource;
     ctrl.DataBind();
     if (UseOthersOption)
     {
         ctrl.Items.Insert(0, new ListItem(OthersLabel, "-1"));
     }
 }
Esempio n. 16
0
        /// <summary>
        /// 绑定控件信息
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="rootcode"></param>
        public void BindListControl(System.Web.UI.WebControls.ListControl lc, string rootcode)
        {
            var list = bllDataDict.GetList(p => p.DataDict_ParentCode == rootcode).OrderBy(p => p.DataDict_Sequence).ToList();//(" DataDict_ParentCode= " + rootcode + "order by DataDict_Sequence asc"); ;

            //var model = new Sys_DataDict { DataDict_Name = "-请选择-", DataDict_Code = "" };
            //list.Insert(0, model);
            lc.DataSource     = list;
            lc.DataTextField  = "DataDict_Name";
            lc.DataValueField = "DataDict_Name";
            lc.DataBind();

            lc.Items.Insert(0, new ListItem("-请选择-", ""));
        }
Esempio n. 17
0
        public static void BindEnumToListControls(Type enumType, ListControl listcontrol)
        {
            string[] names = Enum.GetNames(enumType);

            listcontrol.DataSource = names.Select((key, value) =>

                                       new { key, value }).ToDictionary(x => x.key, x => x.value);

              listcontrol.DataTextField = "Key";

              listcontrol.DataValueField = "Value";

             listcontrol.DataBind();
        }
Esempio n. 18
0
        /// <summary>
        /// 用枚举邦定DorpDownList
        /// </summary>
        /// <param name="EnumType">枚举类型</param>
        /// <param name="DL">DropdownList控件</param>
        /// <param name="DataTextField">Item文本</param>
        /// <param name="DataValueField">Item值</param>
        public virtual void BindDoprdownList(Type EnumType, System.Web.UI.WebControls.ListControl DL)
        {
            ArrayList List = new ArrayList();

            foreach (int i in Enum.GetValues(EnumType))
            {
                ListItem listitem = new ListItem(Enum.GetName(EnumType, i), i.ToString());
                List.Add(listitem);
            }
            DL.DataSource     = List;
            DL.DataTextField  = "text";
            DL.DataValueField = "value";
            DL.DataBind();
            DL.Dispose();
        }
Esempio n. 19
0
 private static void AssemblingList(System.Web.UI.WebControls.ListControl myListControl, DataSet myData)
 {
     try
     {
         myListControl.Items.Clear();
         myListControl.DataSource     = myData;
         myListControl.DataTextField  = "myText";
         myListControl.DataValueField = "myValue";
         myListControl.DataBind();
     }
     catch (Exception ex)
     { var em = ex.Message; }
     finally
     { }
 }
Esempio n. 20
0
 private static void AssemblingMyList(System.Web.UI.WebControls.ListControl myListControl, List <List2Item> myList, string ValueField, string TextField)
 {
     try
     {
         myListControl.Items.Clear();
         myListControl.DataSource     = myList;
         myListControl.DataTextField  = TextField;
         myListControl.DataValueField = ValueField;
         myListControl.DataBind();
     }
     catch (Exception ex)
     { var em = ex.Message; }
     finally
     { }
 }
        public SingleSelectControl(SingleSelect question)
        {
            RepeatDirection direction = question.Vertical ? RepeatDirection.Vertical : RepeatDirection.Horizontal;

            switch (question.SelectionType)
            {
                case Items.SingleSelectType.DropDown:
                    lc = new DropDownList();
                    break;
                case Items.SingleSelectType.ListBox:
                    var lb = new ListBox();
                    lb.SelectionMode = ListSelectionMode.Single;
                    lc = lb;
                    break;
                case Items.SingleSelectType.RadioButtons:
                    var rbl = new RadioButtonList();
                    rbl.RepeatLayout = RepeatLayout.Flow;
                    rbl.RepeatDirection = direction;
                    lc = rbl;
                    break;
            }

            lc.CssClass = "alternatives";
            if (question.ID > 0)
                lc.ID = "q" + question.ID;
            lc.DataTextField = "Title";
            lc.DataValueField = "ID";
			lc.DataSource = question.Children.WhereAccessible();
            lc.DataBind();

            l = new Label();
            l.CssClass = "label";
            l.Text = question.Title;
            if (question.ID > 0)
                l.AssociatedControlID = lc.ID;

            Controls.Add(l);
            Controls.Add(lc);

            if (question.Required)
            {
                cv = new CustomValidator { Display = ValidatorDisplay.Dynamic, Text = "*" };
                cv.ErrorMessage = question.Title + " is required";
                cv.ServerValidate += (s, a) => a.IsValid = !string.IsNullOrEmpty(AnswerText);
                cv.ValidationGroup = "Form";
                Controls.Add(cv);
            }
        }
Esempio n. 22
0
 private static void AssemblingMyListJson(System.Web.UI.WebControls.ListControl myListControl, List <NvListItem> myList)
 {
     try
     {
         // List<List2Item> myList = myList;
         myListControl.Items.Clear();
         myListControl.DataSource     = myList;
         myListControl.DataTextField  = "Name";
         myListControl.DataValueField = "Value";
         myListControl.DataBind();
     }
     catch (Exception ex)
     { var em = ex.Message; }
     finally
     { }
 }
Esempio n. 23
0
        public static void BindDropDownList(ListControl list, string schemaName, string tableName, string valueField, string displayField)
        {
            if(list == null)
            {
                return;
            }

            using(DataTable table = MixERP.Net.BusinessLayer.Helpers.FormHelper.GetTable(schemaName, tableName))
            {
                table.Columns.Add("text_field", typeof(string), displayField);

                list.DataSource = table;
                list.DataValueField = valueField;
                list.DataTextField = "text_field";
                list.DataBind();
            }
        }
Esempio n. 24
0
        /// <summary>
        ///     Eume绑定到WebControl
        /// </summary>
        /// <param name="control">要绑定的ddl</param>
        /// <param name="eumType">枚举的Type</param>
        /// <param name="defShowText">第一行要显示的文字</param>
        /// <param name="defShowValue">第一行要显示的值</param>
        /// <param name="selectedValue">默认选择值</param>
        public static void Bind(this ListControl control, Type eumType, object selectedValue = null, string defShowText = null, object defShowValue = null)
        {
            control.DataSource     = eumType.ToListItem();
            control.DataValueField = "Value";
            control.DataTextField  = "Text";
            control.DataBind();
            if (control.Items.Count > 0)
            {
                control.SelectedIndex = 0;
            }

            control.InsertItem(defShowValue, defShowText);
            if (selectedValue != null)
            {
                control.SelectedItems(selectedValue);
            }
        }
Esempio n. 25
0
        /// <summary>
        ///     IEnumerable绑定到WebControl
        /// </summary>
        /// <param name="control">要绑定的ddl</param>
        /// <param name="lst">源数据</param>
        /// <param name="dataTextField">绑定的文本字段</param>
        /// <param name="dataValueField">绑定的值字段</param>
        /// <param name="defShowText">第一行显示的文字</param>
        /// <param name="defShowValue">第一行显示的值</param>
        /// <param name="selectedValue">默认选择值</param>
        public static void Bind(this ListControl control, IEnumerable lst, object selectedValue = null, string dataTextField = "Caption", string dataValueField = "ID", string defShowText = null, object defShowValue = null)
        {
            control.DataSource     = lst;
            control.DataTextField  = dataTextField;
            control.DataValueField = dataValueField;
            control.DataBind();

            if (control is DropDownList && control.Items.Count > 0)
            {
                control.SelectedIndex = 0;
            }

            control.InsertItem(defShowValue, defShowText);
            if (selectedValue != null)
            {
                control.SelectedItems(selectedValue);
            }
        }
Esempio n. 26
0
        public void BindListControl(System.Web.UI.WebControls.ListControl listControl, string textFiled, string valueFiled, string where, bool isAddPleaseSlect)
        {
            if (!string.IsNullOrEmpty(where))
            {
                where = " where " + where;
            }
            DataTable dt = helper.ExeDataTable("select distinct " + textFiled + "," + valueFiled + " from " + tableName + " " + where, false);

            helper.Dispose();
            listControl.DataSource     = dt;
            listControl.DataTextField  = textFiled;
            listControl.DataValueField = valueFiled;
            listControl.DataBind();
            if (isAddPleaseSlect)
            {
                listControl.Items.Insert(0, new ListItem("请选择", ""));
            }
        }
Esempio n. 27
0
        public static void BindDropDownList(ListControl list, DataTable table, string valueField, string displayField)
        {
            if(list == null)
            {
                return;
            }

            if(table == null)
            {
                return;
            }

            table.Columns.Add("text_field", typeof(string), displayField);

            list.DataSource = table;
            list.DataValueField = valueField;
            list.DataTextField = "text_field";
            list.DataBind();
        }
        private static void PopulateThemeDropDown(ListControl dropDownList, string themeColor)
        {
            var items = SPContext.Current.Site.RootWeb.Lists[ListName].GetItems(new SPQuery { Query = "<where></where>" });

            var list = items
                .Cast<SPListItem>()
                .Select(item => new ListItem { Text = item.Title, Value = item.ID.ToString() })
                .ToList();

            dropDownList.DataSource = list;
            dropDownList.DataValueField = "Value";
            dropDownList.DataTextField = "Text";
            dropDownList.DataBind();
            for (var index = 0; index < dropDownList.Items.Count; ++index)
            {
                if (dropDownList.Items[index].Value == themeColor)
                {
                    dropDownList.SelectedIndex = index;
                }
            }
        }
Esempio n. 29
0
 /// <summary>
 /// Loads the drop down.
 /// </summary>
 /// <param name="ddl">The DDL.</param>
 /// <param name="collection">The collection.</param>
 /// <param name="textField">The text field.</param>
 /// <param name="valueField">The value field.</param>
 /// <param name="initialSelection">The initial selection.</param>
 public static void LoadDropDown(ListControl ddl,
     ICollection collection,
     string textField,
     string valueField,
     string initialSelection)
 {
     ddl.DataSource = collection;
     ddl.DataTextField = textField;
     ddl.DataValueField = valueField;
     ddl.DataBind();
     ddl.SelectedValue = initialSelection;
 }
		public static void BindList(ListControl ctrl, object dataSource) {
			ctrl.DataSource = dataSource;
			ctrl.DataBind();
		}
Esempio n. 31
0
        /// <summary>列表框</summary>
        /// <param name="entity"></param>
        /// <param name="field"></param>
        /// <param name="control"></param>
        /// <param name="canSave"></param>
        protected virtual void SetFormItemListControl(IEntity entity, FieldItem field, ListControl control, Boolean canSave)
        {
            if (control.Items.Count < 1 || !String.IsNullOrEmpty(control.DataSourceID))
            {
                control.DataBind();
                // 这个赋值会影响RequiresDataBinding,而RequiresDataBinding会导致列表控件在OnPreRender阶段重新绑定,造成当前设定的值丢失。
                //control.AppendDataBoundItems = false;
            }
            if (control.Items.Count < 1) return;

            String value = String.Empty + entity[field.Name];
            try
            {
                control.SelectedValue = value;
                if (control.GetType() == typeof(DropDownList) || control.GetType() == typeof(ListControl))
                {
                    /*
                     * 对于ListControl和DropDownList,仅PostBack时有可能抛出异常,初次打开有可能在PerformDataBinding中抛出异常,所以要做额外检测
                     *
                     * 因为DropDownList.SelectedIndex get时有可能修改Items[0].Selected, 所以下面代码最好避免访问SelectedIndex,SelectedValue
                     *
                     * 对于XControl.DropDownList始终没问题
                     * */

                    var selected = false;
                    for (int i = 0; i < control.Items.Count; i++)
                    {
                        var item = control.Items[i];
                        if (item.Selected)
                        {
                            selected = item.Value == value;
                            break;
                        }
                    }
                    if (!selected)
                    {
                        // 没有任何选中项或选中项不是设置的值
                        throw new ArgumentException();
                    }
                }
            }
            catch (ArgumentException)
            {
                var li = control.Items.FindByValue(value);
                if (li == null)
                {
                    li = new ListItem(value, value);
                    control.Items.Add(li);
                }
                control.ClearSelection();
                li.Selected = true;
            }
        }
        private void BindStates(ListControl ddlState, int? stateId)
        {
            ddlState.DataSource = State.LoadStates(null, this.PortalId);
            ddlState.DataValueField = "StateId";
            ddlState.DataTextField = "StateName";
            ddlState.DataBind();

            if (stateId.HasValue)
            {
                ddlState.SelectedValue = stateId.Value.ToString(CultureInfo.InvariantCulture);
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="list">
        /// </param>
        /// <param name="listDataSource">
        /// </param>
        /// <param name="selectedValue">
        /// </param>
        /// <param name="selectedText">
        /// </param>
        public static void BindToListControl(ListControl list, IEnumerable<KeyValuePair<string, string>> listDataSource,
            string selectedValue, string selectedText)
        {
            list.Items.Clear();
              list.DataSource = listDataSource;
              list.DataValueField = "Key";
              list.DataTextField = "Value";
              list.DataBind();
              if (!string.IsNullOrEmpty(selectedValue))
              {
            string[] selectedValues = selectedValue.Split('|');
            foreach (string val in selectedValues)
            {
              if (!string.IsNullOrEmpty(val))
              {
            ListItem selctedItem = list.Items.FindByValue(val);
            if (selctedItem != null)
            {
              selctedItem.Selected = true;
            }
              }
            }

            return;
              }

              if (!string.IsNullOrEmpty(selectedText))
              {
            ListItem selectedItem = list.Items.FindByText(selectedText);
            if (selectedItem != null)
            {
              selectedItem.Selected = true;
            }

            return;
              }
        }
 public static void BindToEnum(Type enumType, ListControl lc)
 {
     // get the names from the enumeration
     string[] names = Enum.GetNames(enumType);
     // get the values from the enumeration
     Array values = Enum.GetValues(enumType);
     // turn it into a hash table
     Hashtable ht = new Hashtable();
     for (int i = 0; i < names.Length; i++)
         // note the cast to integer here is important
         // otherwise we'll just get the enum string back again
         ht.Add(names[i], (int)values.GetValue(i));
     // return the dictionary to be bound to
     lc.DataSource = ht;
     lc.DataTextField = "Key";
     lc.DataValueField = "Value";
     lc.DataBind();
 }
Esempio n. 35
0
 /// <summary>
 /// Executes a query and binds it to a ListControl.
 /// </summary>
 /// <param name="listControl">The list control you wish to use. For example a dropdown box.</param>
 /// <param name="valueField">The name of the field representing the value.</param>
 /// <param name="textField">The name of the field representing the text to show.</param>
 /// <param name="selectedValue">The selectedValue for this web control.</param>
 /// <param name="sql">Your sql query string</param>
 /// <param name="connectionString">Your database connection string.</param>
 /// <param name="connectionType">The type of database you are using.</param>
 public static void ExecuteAndBind(ListControl listControl, string valueField, string textField,
     string selectedValue, string sql, string connectionString,
     DataBaseConnectionType connectionType)
 {
     Query q = ExecuteReader(sql, connectionString, connectionType);
     listControl.DataSource = q.DataReader;
     listControl.DataTextField = textField ?? q.DataReader.GetName(1);
     listControl.DataValueField = valueField ?? q.DataReader.GetName(0);
     listControl.DataBind();
     if (selectedValue != null)
     {
         foreach (ListItem item in listControl.Items)
         {
             if (item != null && item.Value != null)
                 item.Selected = Equals(item.Value.ToLowerInvariant() , selectedValue.ToLowerInvariant() );
         }
     }
     q.Close();
 }
        /// <summary>
        /// Populates the gallery drop downs on this page
        /// </summary>
        /// <param name="dropdown">Dropdownlist Reference</param>
        private void PopulateGalleryDropDown(ListControl dropdown)
        {
            //Need to Cache this...
            List<Gallery> galleries = new GalleryLogic().RetrieveGalleriesByUserId(CurrentUser.UserId);

            dropdown.DataSource = galleries;
            dropdown.DataTextField = "Name";
            dropdown.DataValueField = "GalleryID";
            dropdown.DataBind();
        }
Esempio n. 37
0
        private static void BindList(ListControl control, DataSet ds, string texto, string valor)
        {
            try {

            control.DataSource = ds;
            control.DataTextField = texto;
            control.DataValueField = valor;
            control.DataBind();
            control.Items[0].Selected = true;
            }
            catch (Exception ex)
            {
            }
        }
		/// <summary>
		/// 将枚举数据绑定至列表型控件
		/// </summary>
		/// <param name="enumType">枚举类型</param>
		/// <param name="data">当前数据</param>
		/// <param name="ddl">下拉控件</param>
		/// <param name="item">绑定数据</param>
		private void BindEnumToListControl(System.Type enumType, object data, ListControl lControl, DataBindingItem item)
		{
			if (item.EnumAutoBinding)
			{
				EnumItemDescriptionList listEnum = EnumItemDescriptionAttribute.GetDescriptionList(enumType);

				List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();

				foreach (EnumItemDescription enumItem in listEnum)
				{
					KeyValuePair<int, string> kp = new KeyValuePair<int, string>(enumItem.EnumValue,
						string.IsNullOrEmpty(enumItem.Description) ? enumItem.Name : enumItem.Description);

					list.Add(kp);
				}

				lControl.DataSource = BuildEnumList(enumType, item.EnumUsage);

				lControl.DataValueField = "Key";
				lControl.DataTextField = "Value";
				lControl.DataBind();
			}

			int intData = Convert.ToInt32(data);

			if ((lControl is CheckBoxList) && FlagsAttribute.IsDefined(enumType, typeof(FlagsAttribute)))
			{
				foreach (ListItem lItem in lControl.Items)
				{
					int v = int.Parse(lItem.Value);

					if ((v & intData) != 0)
						lItem.Selected = true;
				}
			}
			else
			{
				string strValue = intData.ToString();

				foreach (ListItem lItem in lControl.Items)
				{
					if (lItem.Value == strValue)
					{
						lControl.SelectedValue = strValue;
						break;
					}
				}
			}
		}
Esempio n. 39
0
 //Dream4.0 changes replaced list box control to list control
 /// <summary>
 /// Populates the list control.
 /// </summary>
 /// <param name="listcontrol">The listcontrol.</param>
 /// <param name="xmlDocResponse">The XML doc response.</param>
 /// <param name="xpath">The xpath.</param>
 /// <param name="selectedItem">The selected item.</param>
 protected void PopulateListControl(ListControl listcontrol, XmlDocument responseXml, string xpath, string selectedItem)
 {
     XmlNodeList objXmlNodeList = null;
     if(responseXml != null)
     {
         objXmlNodeList = responseXml.SelectNodes(xpath);
         if(objXmlNodeList != null)
         {
             listcontrol.DataSource = objXmlNodeList;
             listcontrol.DataTextField = "value";
             listcontrol.DataValueField = "value";
             listcontrol.DataBind();
             if(listcontrol.Items.FindByText(selectedItem) != null)
             {
                 listcontrol.Items.FindByText(selectedItem).Selected = true;
             }
         }
     }
 }
Esempio n. 40
0
        /// <summary>列表框</summary>
        /// <param name="entity"></param>
        /// <param name="field"></param>
        /// <param name="control"></param>
        /// <param name="canSave"></param>
        protected virtual void SetFormItemListControl(IEntity entity, FieldItem field, ListControl control, Boolean canSave)
        {
            if (control.Items.Count < 1 || !String.IsNullOrEmpty(control.DataSourceID))
            {
                control.DataBind();
                // 这个赋值会影响RequiresDataBinding,而RequiresDataBinding会导致列表控件在OnPreRender阶段重新绑定,造成当前设定的值丢失。
                //control.AppendDataBoundItems = false;
            }
            if (control.Items.Count < 1) return;

            String value = String.Empty + entity[field.Name];

            ListItem li = control.Items.FindByValue(value);
            if (li != null)
                li.Selected = true;
            else
            {
                li = new ListItem(value, value);
                control.Items.Add(li);
                li.Selected = true;
            }
        }
        private void DisplayLocationTypes(ListControl ddl)
        {
            ddl.DataSource = LocationType.GetLocationTypes();
            ddl.DataTextField = "LocationTypeName";
            ddl.DataValueField = "LocationTypeId";
            ddl.DataBind();

            string displayTypes = this.Settings["DisplayTypes"].ToString();
            string[] displayTypesArray = displayTypes.Split(',');

            ddl.Items.Insert(0, new ListItem(Localization.GetString("ChooseOne", this.LocalResourceFile), "-1"));

            if (ddl.Items.Count == 0)
            {
                this.singleError.Visible = true;
            }
            else
            {
                this.singleError.Visible = false;
            }

            // If this module has been configured to display only one location and a user is adding a new entry
            // we are defaulting the locationtype based on the setting. hk
            if (displayTypes.Length == 1)
            {
                string id = displayTypesArray[0];
                ListItem li = ddl.Items.FindByValue(id);
                if (li != null)
                {
                    li.Selected = true;
                }
            }
        }