Exemplo n.º 1
0
            /// <summary>
            /// Construct a DropDownListTempate from id, list, insertNullKey.
            /// </summary>
            /// <param name="id">Data Field Name</param>
            /// <param name="list">Items to list</param>
            /// <param name="insertNullKey">Whether to prepend a -v- item to the list</param>
            public DropDownListTemplate(string id, IKeyValueList list, bool insertNullKey)
            {
                if (insertNullKey)
                {
                    lock(list)
                    {
                        IKeyValue e = list[0] as KeyValue;
                        if (!NULL_TOKEN.Equals(e.Text))
                        {
                            list.Insert(0, new KeyValue(String.Empty, NULL_TOKEN));
                        }
                    }
                }

                _DataField = id;
                _Control = new DropDownList();
                _Control.ID = id;
                _Control.DataSource = list;
                _Control.DataTextField = "value";
                _Control.DataValueField = "key";
                _Control.DataBind();
                _Control.DataBinding += new EventHandler(OnDataBinding);
                _Control.PreRender += new EventHandler(OnPreRender);
            }