System.Web.UI.WebControls.ImageField.OnDataBindField C# (CSharp) Method

OnDataBindField() protected method

protected OnDataBindField ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
		protected virtual void OnDataBindField (object sender, EventArgs e)
		{
			Control control = (Control) sender;
			ControlCollection controls = control != null ? control.Controls : null;
			Control namingContainer = control.NamingContainer;
			Control c;
			if (sender is DataControlFieldCell) {
				if (controls.Count == 0)
					return;
				c = controls [0];
			} else if (sender is Image || sender is TextBox)
				c = control;
			else
				return;

			if (imageProperty == null)
				imageProperty = GetProperty (namingContainer, DataImageUrlField);
			
			if (c is TextBox) {
				object val = GetValue (namingContainer, DataImageUrlField, ref imageProperty);
				((TextBox)c).Text = val != null ? val.ToString() : String.Empty;
			}
			else if (c is Image) {
				Image img = (Image)c;
				string value =  FormatImageUrlValue (GetValue (namingContainer, DataImageUrlField, ref imageProperty));
				if (value == null || (ConvertEmptyStringToNull && value.Length == 0)) {
					if (NullImageUrl == null || NullImageUrl.Length == 0) {
						c.Visible = false;
						Label label = new Label ();
						label.Text = NullDisplayText;
						controls.Add (label);
					}
					else
						value = NullImageUrl;
				}
				img.ImageUrl = value;
				img.AlternateText = GetFormattedAlternateText (namingContainer);
			}
		}