Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / UI / WebControls / AutoGeneratedField.cs / 3 / AutoGeneratedField.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Security.Permissions; ////// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [EditorBrowsable(EditorBrowsableState.Never)] public sealed class AutoGeneratedField : BoundField { private bool _suppressPropertyThrows = false; private bool _useCheckBox; private bool _useCheckBoxValid; ///Creates a field bounded to a data field in a ///. /// public AutoGeneratedField(string dataField) { DataField = dataField; } ///Initializes a new instance of a ///class. /// public override string DataFormatString { get { return base.DataFormatString; } set { if (!_suppressPropertyThrows) { throw new NotSupportedException(); } } } ///Gets or sets the display format of data in this /// field. ////// public Type DataType { get { object o = ViewState["DataType"]; if (o != null) { return (Type)o; } return typeof(string); } set { ViewState["DataType"] = value; } } ///Gets or sets the type of data being displayed by the field. ////// public override bool InsertVisible { get { return base.InsertVisible; } set { if (!_suppressPropertyThrows) { throw new NotSupportedException(); } } } ///Gets or sets whether the field is visible in Insert mode. Turn off for auto-gen'd db fields ////// public override bool ConvertEmptyStringToNull { get { return base.ConvertEmptyStringToNull; } set { if (!_suppressPropertyThrows) { throw new NotSupportedException(); } } } ///Gets or sets the property that determines whether the BoundField treats empty string as /// null when the field values are extracted. ////// private bool UseCheckBox { get { if (!_useCheckBoxValid) { _useCheckBox = (DataType == typeof(bool) || DataType == typeof(bool?)); _useCheckBoxValid = true; } return _useCheckBox; } } protected override void CopyProperties(DataControlField newField) { ((AutoGeneratedField)newField).DataType = DataType; _suppressPropertyThrows = true; ((AutoGeneratedField)newField)._suppressPropertyThrows = true; base.CopyProperties(newField); _suppressPropertyThrows = false; ((AutoGeneratedField)newField)._suppressPropertyThrows = false; } protected override DataControlField CreateField() { return new AutoGeneratedField(DataField); } ///Determines whether the field should display a text box. ////// Returns a value to be used for design-time rendering /// protected override object GetDesignTimeValue() { if (UseCheckBox) { return true; } return base.GetDesignTimeValue(); } ////// Extracts the value of the databound cell and inserts the value into the given dictionary /// public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { if (UseCheckBox) { Control childControl = null; string dataField = DataField; object value = null; if (cell.Controls.Count > 0) { childControl = cell.Controls[0]; CheckBox checkBox = childControl as CheckBox; if (checkBox != null) { if (includeReadOnly || checkBox.Enabled) { value = checkBox.Checked; } } } if (value != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = value; } else { dictionary.Add(dataField, value); } } } else { base.ExtractValuesFromCell(dictionary, cell, rowState, includeReadOnly); } } protected override void InitializeDataCell(DataControlFieldCell cell, DataControlRowState rowState) { if (UseCheckBox) { CheckBox childControl = null; CheckBox boundControl = null; if (((rowState & DataControlRowState.Edit) != 0 && ReadOnly == false) || (rowState & DataControlRowState.Insert) != 0) { CheckBox editor = new CheckBox(); childControl = editor; if (DataField.Length != 0 && (rowState & DataControlRowState.Edit) != 0) { boundControl = editor; } } else if (DataField.Length != 0) { CheckBox editor = new CheckBox(); editor.Enabled = false; childControl = editor; boundControl = editor; } if (childControl != null) { childControl.ToolTip = HeaderText; cell.Controls.Add(childControl); } if (boundControl != null) { boundControl.DataBinding += new EventHandler(this.OnDataBindField); } } else { base.InitializeDataCell(cell, rowState); } } ////// protected override void OnDataBindField(object sender, EventArgs e) { if (UseCheckBox) { Control boundControl = (Control)sender; Control controlContainer = boundControl.NamingContainer; object data = GetValue(controlContainer); if (!(boundControl is CheckBox)) { throw new HttpException(SR.GetString(SR.CheckBoxField_WrongControlType, DataField)); } if (DataBinder.IsNull(data)) { ((CheckBox)boundControl).Checked = false; } else { if (data is Boolean) { ((CheckBox)boundControl).Checked = (Boolean)data; } else { try { ((CheckBox)boundControl).Checked = Boolean.Parse(data.ToString()); } catch (FormatException fe) { throw new HttpException(SR.GetString(SR.CheckBoxField_CouldntParseAsBoolean, DataField), fe); } } } } else { base.OnDataBindField(sender, e); } } ////// public override void ValidateSupportsCallback() { } } }Override with an empty body if the field's controls all support callback. /// Otherwise, override and throw a useful error message about why the field can't support callbacks. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Vector.cs
- ViewKeyConstraint.cs
- LinearGradientBrush.cs
- StringUtil.cs
- Soap12FormatExtensions.cs
- WindowsStatusBar.cs
- MergablePropertyAttribute.cs
- MessageContractExporter.cs
- HttpApplicationFactory.cs
- HttpInputStream.cs
- Activity.cs
- OrderPreservingPipeliningMergeHelper.cs
- ArrayList.cs
- DesignerActionVerbList.cs
- TemplateModeChangedEventArgs.cs
- ParentQuery.cs
- TaskDesigner.cs
- BuildProviderAppliesToAttribute.cs
- QueuePropertyVariants.cs
- VisualStates.cs
- DiscreteKeyFrames.cs
- SimpleType.cs
- ModelUIElement3D.cs
- Variable.cs
- ClientTargetSection.cs
- DataViewManagerListItemTypeDescriptor.cs
- PictureBox.cs
- RowToFieldTransformer.cs
- hresults.cs
- BinaryFormatter.cs
- ReadOnlyHierarchicalDataSource.cs
- SchemaLookupTable.cs
- CapiNative.cs
- DisplayInformation.cs
- DataGridHeaderBorder.cs
- Latin1Encoding.cs
- Currency.cs
- RawStylusInput.cs
- SemanticBasicElement.cs
- IIS7WorkerRequest.cs
- FileRecordSequenceCompletedAsyncResult.cs
- ServicePointManagerElement.cs
- StrongName.cs
- ScrollableControl.cs
- FilterQueryOptionExpression.cs
- SqlTrackingWorkflowInstance.cs
- PropertyPushdownHelper.cs
- LocalIdKeyIdentifierClause.cs
- AssemblyCache.cs
- FileUtil.cs
- PerfCounterSection.cs
- PathData.cs
- SamlAdvice.cs
- MsmqInputChannel.cs
- Operand.cs
- ChangeProcessor.cs
- XmlSchemaExporter.cs
- RegexCaptureCollection.cs
- QuadraticBezierSegment.cs
- TypeTypeConverter.cs
- Symbol.cs
- SectionRecord.cs
- PolicyLevel.cs
- SystemColors.cs
- ThemeableAttribute.cs
- RadioButtonStandardAdapter.cs
- TransformerConfigurationWizardBase.cs
- WorkflowDataContext.cs
- Metafile.cs
- SqlTriggerAttribute.cs
- FloatAverageAggregationOperator.cs
- Decoder.cs
- ToolStripItemImageRenderEventArgs.cs
- GeneralTransform2DTo3DTo2D.cs
- IntSecurity.cs
- DbProviderFactory.cs
- ChangesetResponse.cs
- WindowsNonControl.cs
- FilteredReadOnlyMetadataCollection.cs
- CellQuery.cs
- VersionedStreamOwner.cs
- AppDomainManager.cs
- XPathEmptyIterator.cs
- FontFaceLayoutInfo.cs
- TreeViewEvent.cs
- SystemResourceKey.cs
- _TransmitFileOverlappedAsyncResult.cs
- Bitmap.cs
- SQLRoleProvider.cs
- TypeExtensionConverter.cs
- NetworkStream.cs
- DbProviderManifest.cs
- BoundsDrawingContextWalker.cs
- ResolveResponseInfo.cs
- ToolStripSeparatorRenderEventArgs.cs
- SqlTypesSchemaImporter.cs
- IssuanceTokenProviderState.cs
- DbDataReader.cs
- ColumnHeaderConverter.cs
- CheckBoxAutomationPeer.cs