Exemplo n.º 1
0
        /// <summary>
        /// Handles the data binding.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void HandleDataBinding(object sender, EventArgs e)
        {
            Control ctrl = (Control)sender;
            object  val  = GetValue(ctrl.NamingContainer) ?? string.Empty;

            if (data == null)
            {
                //Cache the data from the DataSourceControl, so that we only get the data once.  If
                //we just set the DataSourceID on the dropdown, the select command would get called
                //once for each row.
                DataSourceControl dsc = this.Control.NamingContainer.FindControl(this.DataSourceID) as DataSourceControl;
                DataSourceView    dsv = ((IDataSource)dsc).GetView("DefaultView");
                dsv.Select(DataSourceSelectArguments.Empty, new DataSourceViewSelectCallback(this.DataSourceCallback));
            }

            if (ctrl is EntityDropDownList)
            {
                EntityDropDownList eddl = (EntityDropDownList)ctrl;
                eddl.DataTextField  = this.DataTextField;
                eddl.DataValueField = this.DataValueField;
                eddl.DataSource     = this.data;
                eddl.AppendNullItem = this.AppendNullItem;
            }
            else if (ctrl is Label)
            {
                Label label             = (Label)ctrl;
                EntityDropDownList temp = new EntityDropDownList();
                temp.DataTextField  = this.DataTextField;
                temp.DataValueField = this.DataValueField;
                temp.DataSource     = this.data;
                temp.Visible        = false;
                temp.AppendNullItem = this.AppendNullItem;
                label.Controls.Add(temp);
                temp.DataBind();

                label.Text = String.Empty;
                foreach (ListItem listItem in temp.Items)
                {
                    if (0 == String.Compare(listItem.Value, val.ToString()))
                    {
                        label.Text = listItem.Text;
                    }
                }
            }
        }
        /// <summary>
        /// Handles the data binding.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void HandleDataBinding( object sender, EventArgs e )
        {
            Control ctrl = (Control)sender;
            object val = GetValue( ctrl.NamingContainer ) ?? string.Empty;

            if ( data == null )
            {
                //Cache the data from the DataSourceControl, so that we only get the data once.  If 
                //we just set the DataSourceID on the dropdown, the select command would get called 
                //once for each row.
                DataSourceControl dsc = this.Control.NamingContainer.FindControl( this.DataSourceID ) as DataSourceControl;
                DataSourceView dsv = ( (IDataSource)dsc ).GetView( "DefaultView" );
                dsv.Select( DataSourceSelectArguments.Empty, new DataSourceViewSelectCallback( this.DataSourceCallback ) );
            }

            if ( ctrl is EntityDropDownList )
            {
                EntityDropDownList eddl = (EntityDropDownList)ctrl;
                eddl.DataTextField = this.DataTextField;
                eddl.DataValueField = this.DataValueField;
                eddl.DataSource = this.data;
                eddl.AppendNullItem = this.AppendNullItem;
            }
            else if ( ctrl is Label )
            {
                Label label = (Label)ctrl;
                EntityDropDownList temp = new EntityDropDownList();
                temp.DataTextField = this.DataTextField;
                temp.DataValueField = this.DataValueField;
                temp.DataSource = this.data;
                temp.Visible = false;
                temp.AppendNullItem = this.AppendNullItem;
                label.Controls.Add( temp );
                temp.DataBind();

                label.Text = String.Empty;
                foreach ( ListItem listItem in temp.Items )
                {
                    if ( 0 == String.Compare( listItem.Value, val.ToString() ) )
                    {
                        label.Text = listItem.Text;
                    }
                }
            }
        }