Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / UI / WebControls / TemplateField.cs / 1 / TemplateField.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.Globalization; using System.Security.Permissions; ////// // [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class TemplateField : DataControlField { private ITemplate headerTemplate; private ITemplate footerTemplate; private ITemplate itemTemplate; private ITemplate editItemTemplate; private ITemplate alternatingItemTemplate; private ITemplate insertItemTemplate; ///Defines the template for controls layout within a /// ////// field. /// Initializes a new instance of the public TemplateField() { } ///class. /// /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_AlternatingItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate AlternatingItemTemplate { get { return alternatingItemTemplate; } set { alternatingItemTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how alternating items are rendered. /// [ WebCategory("Behavior"), DefaultValue(true), WebSysDescription(SR.ImageField_ConvertEmptyStringToNull) ] public virtual bool ConvertEmptyStringToNull { get { object o = ViewState["ConvertEmptyStringToNull"]; if (o != null) { return (bool)o; } return true; } set { ViewState["ConvertEmptyStringToNull"] = value; } } ///Gets or sets the property that determines whether the field treats empty string as /// null when the field values are extracted. ////// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_EditItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate EditItemTemplate { get { return editItemTemplate; } set { editItemTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how rows in edit mode are rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_FooterTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer)) ] public virtual ITemplate FooterTemplate { get { return footerTemplate; } set { footerTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how the control footer is rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_HeaderTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer)) ] public virtual ITemplate HeaderTemplate { get { return headerTemplate; } set { headerTemplate = value; OnFieldChanged(); } } ///Specifies the ////// that defines how the control header is rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_InsertItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate InsertItemTemplate { get { return insertItemTemplate; } set { insertItemTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how rows in insert mode are rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_ItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate ItemTemplate { get { return itemTemplate; } set { itemTemplate = value; OnFieldChanged(); } } protected override void CopyProperties(DataControlField newField) { ((TemplateField)newField).ConvertEmptyStringToNull = ConvertEmptyStringToNull; ((TemplateField)newField).AlternatingItemTemplate = AlternatingItemTemplate; ((TemplateField)newField).ItemTemplate = ItemTemplate; ((TemplateField)newField).FooterTemplate = FooterTemplate; ((TemplateField)newField).EditItemTemplate = EditItemTemplate; ((TemplateField)newField).HeaderTemplate = HeaderTemplate; ((TemplateField)newField).InsertItemTemplate = InsertItemTemplate; base.CopyProperties(newField); } protected override DataControlField CreateField() { return new TemplateField(); } ///Specifies the ///that defines how items are rendered. /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { DataBoundControlHelper.ExtractValuesFromBindableControls(dictionary, cell); IBindableTemplate bindableTemplate = ItemTemplate as IBindableTemplate; if (((rowState & DataControlRowState.Alternate) != 0) && (AlternatingItemTemplate != null)) { bindableTemplate = AlternatingItemTemplate as IBindableTemplate; } if (((rowState & DataControlRowState.Edit) != 0) && EditItemTemplate != null) { bindableTemplate = EditItemTemplate as IBindableTemplate; } else if ((rowState & DataControlRowState.Insert) != 0 && InsertVisible) { if (InsertItemTemplate != null) { bindableTemplate = InsertItemTemplate as IBindableTemplate; } else { if (EditItemTemplate != null) { bindableTemplate = EditItemTemplate as IBindableTemplate; } } } if (bindableTemplate != null) { bool convertEmptyStringToNull = ConvertEmptyStringToNull; foreach (DictionaryEntry entry in bindableTemplate.ExtractValues(cell.BindingContainer)) { object value = entry.Value; if (convertEmptyStringToNull && value is string && ((string)value).Length == 0) { dictionary[entry.Key] = null; } else { dictionary[entry.Key] = value; } } } return; } ////// /// public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) { base.InitializeCell(cell, cellType, rowState, rowIndex); ITemplate contentTemplate = null; switch (cellType) { case DataControlCellType.Header: contentTemplate = headerTemplate; break; case DataControlCellType.Footer: contentTemplate = footerTemplate; break; case DataControlCellType.DataCell: contentTemplate = itemTemplate; if ((rowState & DataControlRowState.Edit) != 0) { if (editItemTemplate != null) { contentTemplate = editItemTemplate; } } else if ((rowState & DataControlRowState.Insert) != 0) { if (insertItemTemplate != null) { contentTemplate = insertItemTemplate; } else { if (editItemTemplate != null) { contentTemplate = editItemTemplate; } } } else if ((rowState & DataControlRowState.Alternate) != 0) { if (alternatingItemTemplate != null) { contentTemplate = alternatingItemTemplate; } } break; } if (contentTemplate != null) { // The base class might have added a control or some text for some cases // such as header text which need to be removed before // the corresponding template is used. // Note that setting text also has the effect of clearing out any controls. cell.Text = String.Empty; contentTemplate.InstantiateIn(cell); } else { if (cellType == DataControlCellType.DataCell) { cell.Text = " "; } } } ////// public override void ValidateSupportsCallback() { throw new NotSupportedException(SR.GetString(SR.TemplateField_CallbacksNotSupported, Control.ID)); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //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. ///// 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.Globalization; using System.Security.Permissions; ////// // [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class TemplateField : DataControlField { private ITemplate headerTemplate; private ITemplate footerTemplate; private ITemplate itemTemplate; private ITemplate editItemTemplate; private ITemplate alternatingItemTemplate; private ITemplate insertItemTemplate; ///Defines the template for controls layout within a /// ////// field. /// Initializes a new instance of the public TemplateField() { } ///class. /// /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_AlternatingItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate AlternatingItemTemplate { get { return alternatingItemTemplate; } set { alternatingItemTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how alternating items are rendered. /// [ WebCategory("Behavior"), DefaultValue(true), WebSysDescription(SR.ImageField_ConvertEmptyStringToNull) ] public virtual bool ConvertEmptyStringToNull { get { object o = ViewState["ConvertEmptyStringToNull"]; if (o != null) { return (bool)o; } return true; } set { ViewState["ConvertEmptyStringToNull"] = value; } } ///Gets or sets the property that determines whether the field treats empty string as /// null when the field values are extracted. ////// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_EditItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate EditItemTemplate { get { return editItemTemplate; } set { editItemTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how rows in edit mode are rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_FooterTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer)) ] public virtual ITemplate FooterTemplate { get { return footerTemplate; } set { footerTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how the control footer is rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_HeaderTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer)) ] public virtual ITemplate HeaderTemplate { get { return headerTemplate; } set { headerTemplate = value; OnFieldChanged(); } } ///Specifies the ////// that defines how the control header is rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_InsertItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate InsertItemTemplate { get { return insertItemTemplate; } set { insertItemTemplate = value; OnFieldChanged(); } } ///Specifies the ///that defines how rows in insert mode are rendered. /// [ Browsable(false), DefaultValue(null), WebSysDescription(SR.TemplateField_ItemTemplate), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(IDataItemContainer), BindingDirection.TwoWay) ] public virtual ITemplate ItemTemplate { get { return itemTemplate; } set { itemTemplate = value; OnFieldChanged(); } } protected override void CopyProperties(DataControlField newField) { ((TemplateField)newField).ConvertEmptyStringToNull = ConvertEmptyStringToNull; ((TemplateField)newField).AlternatingItemTemplate = AlternatingItemTemplate; ((TemplateField)newField).ItemTemplate = ItemTemplate; ((TemplateField)newField).FooterTemplate = FooterTemplate; ((TemplateField)newField).EditItemTemplate = EditItemTemplate; ((TemplateField)newField).HeaderTemplate = HeaderTemplate; ((TemplateField)newField).InsertItemTemplate = InsertItemTemplate; base.CopyProperties(newField); } protected override DataControlField CreateField() { return new TemplateField(); } ///Specifies the ///that defines how items are rendered. /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { DataBoundControlHelper.ExtractValuesFromBindableControls(dictionary, cell); IBindableTemplate bindableTemplate = ItemTemplate as IBindableTemplate; if (((rowState & DataControlRowState.Alternate) != 0) && (AlternatingItemTemplate != null)) { bindableTemplate = AlternatingItemTemplate as IBindableTemplate; } if (((rowState & DataControlRowState.Edit) != 0) && EditItemTemplate != null) { bindableTemplate = EditItemTemplate as IBindableTemplate; } else if ((rowState & DataControlRowState.Insert) != 0 && InsertVisible) { if (InsertItemTemplate != null) { bindableTemplate = InsertItemTemplate as IBindableTemplate; } else { if (EditItemTemplate != null) { bindableTemplate = EditItemTemplate as IBindableTemplate; } } } if (bindableTemplate != null) { bool convertEmptyStringToNull = ConvertEmptyStringToNull; foreach (DictionaryEntry entry in bindableTemplate.ExtractValues(cell.BindingContainer)) { object value = entry.Value; if (convertEmptyStringToNull && value is string && ((string)value).Length == 0) { dictionary[entry.Key] = null; } else { dictionary[entry.Key] = value; } } } return; } ////// /// public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) { base.InitializeCell(cell, cellType, rowState, rowIndex); ITemplate contentTemplate = null; switch (cellType) { case DataControlCellType.Header: contentTemplate = headerTemplate; break; case DataControlCellType.Footer: contentTemplate = footerTemplate; break; case DataControlCellType.DataCell: contentTemplate = itemTemplate; if ((rowState & DataControlRowState.Edit) != 0) { if (editItemTemplate != null) { contentTemplate = editItemTemplate; } } else if ((rowState & DataControlRowState.Insert) != 0) { if (insertItemTemplate != null) { contentTemplate = insertItemTemplate; } else { if (editItemTemplate != null) { contentTemplate = editItemTemplate; } } } else if ((rowState & DataControlRowState.Alternate) != 0) { if (alternatingItemTemplate != null) { contentTemplate = alternatingItemTemplate; } } break; } if (contentTemplate != null) { // The base class might have added a control or some text for some cases // such as header text which need to be removed before // the corresponding template is used. // Note that setting text also has the effect of clearing out any controls. cell.Text = String.Empty; contentTemplate.InstantiateIn(cell); } else { if (cellType == DataControlCellType.DataCell) { cell.Text = " "; } } } ////// public override void ValidateSupportsCallback() { throw new NotSupportedException(SR.GetString(SR.TemplateField_CallbacksNotSupported, Control.ID)); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.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
- DrawingGroupDrawingContext.cs
- HtmlInputControl.cs
- SystemDiagnosticsSection.cs
- SimpleType.cs
- DesigntimeLicenseContextSerializer.cs
- ListViewHitTestInfo.cs
- ToggleButton.cs
- formatstringdialog.cs
- HeaderCollection.cs
- DbConnectionOptions.cs
- AspCompat.cs
- ScriptingRoleServiceSection.cs
- SqlServer2KCompatibilityCheck.cs
- CodeTypeReferenceCollection.cs
- AbstractDataSvcMapFileLoader.cs
- ListDictionaryInternal.cs
- NullableFloatMinMaxAggregationOperator.cs
- XamlInt32CollectionSerializer.cs
- SocketStream.cs
- TabPanel.cs
- SplineQuaternionKeyFrame.cs
- SrgsGrammarCompiler.cs
- QilDataSource.cs
- PageParser.cs
- X509CertificateStore.cs
- BitStack.cs
- XmlSchemaElement.cs
- SequenceFullException.cs
- ProxyHelper.cs
- ConfigurationStrings.cs
- Pointer.cs
- ErrorWebPart.cs
- BufferedStream.cs
- TypeReference.cs
- GraphicsContainer.cs
- Boolean.cs
- AnnotationResourceCollection.cs
- FigureParagraph.cs
- TargetParameterCountException.cs
- EntityContainerEmitter.cs
- FunctionDetailsReader.cs
- coordinatorscratchpad.cs
- InProcStateClientManager.cs
- BitmapCacheBrush.cs
- NativeRightsManagementAPIsStructures.cs
- HMACSHA256.cs
- TextTreeInsertElementUndoUnit.cs
- Activation.cs
- TheQuery.cs
- AppDomainUnloadedException.cs
- ProgressBarAutomationPeer.cs
- WindowsBrush.cs
- QueryAsyncResult.cs
- XmlSchemaFacet.cs
- HoistedLocals.cs
- DocumentSchemaValidator.cs
- ObservableDictionary.cs
- CodeGenHelper.cs
- GreenMethods.cs
- FixedDSBuilder.cs
- ManagedIStream.cs
- WebControlsSection.cs
- tibetanshape.cs
- ProfileInfo.cs
- LinqDataSourceContextEventArgs.cs
- DelegateBodyWriter.cs
- ToolStripArrowRenderEventArgs.cs
- CreateCardRequest.cs
- ToolStripRenderEventArgs.cs
- XmlAtomErrorReader.cs
- WebServiceData.cs
- FileVersionInfo.cs
- ChooseAction.cs
- Polygon.cs
- EntityDataSourceChangingEventArgs.cs
- StorageFunctionMapping.cs
- SafeFileMappingHandle.cs
- ConnectionManagementElement.cs
- MarkupProperty.cs
- ToolStripItemTextRenderEventArgs.cs
- OuterGlowBitmapEffect.cs
- OrderByQueryOptionExpression.cs
- LoaderAllocator.cs
- XmlSchemaProviderAttribute.cs
- PackUriHelper.cs
- ImmutableObjectAttribute.cs
- DataBinding.cs
- NameValuePair.cs
- XPathMessageFilterElement.cs
- UriParserTemplates.cs
- SSmlParser.cs
- EngineSite.cs
- CompilerScopeManager.cs
- AssemblySettingAttributes.cs
- ConsoleCancelEventArgs.cs
- validationstate.cs
- XmlNamespaceMappingCollection.cs
- Soap12ProtocolImporter.cs
- WebConvert.cs
- CalloutQueueItem.cs