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

OnDataBindField() protected method

protected OnDataBindField ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
		protected override void OnDataBindField (object sender, EventArgs e)
		{
			try {
				Control container = (Control) sender;
				object val = GetValue (container.NamingContainer);
				CheckBox box = sender as CheckBox;
				if (box == null) {
					DataControlFieldCell cell = sender as DataControlFieldCell;
					if (cell != null) {
						ControlCollection controls = cell.Controls;
						int ccount = controls != null ? controls.Count : 0;
						if (ccount == 1)
							box = controls [0] as CheckBox;
						if (box == null)
							return;
					}
				}
				
				if (box == null)
					throw new HttpException ("CheckBox field '" + DataField + "' contains a control that isn't a CheckBox.  Override OnDataBindField to inherit from CheckBoxField and add different controls.");
				
				if (val != null && val != DBNull.Value)
					box.Checked = (bool) val;
				else
					if (string.IsNullOrEmpty (DataField)) {
						box.Visible = false;
						return;
					}

				if (!box.Visible)
					box.Visible = true;
			} catch (HttpException) {
				throw;
			} catch (Exception ex) {
				throw new HttpException (ex.Message, ex);
			}
		}