• How to: Supply Predefined Values for the String Property Editor Dynamically (ASP.NET) 如何:动态提供字符串属性编辑器的预定义值(ASP.NET)


    This topic describes implementation of a custom ASP.NET Web Property Editor that will be used to edit a business object's CultureCode (locale) property of the String type. The dropdown list of the Property Editor's control will display the cultures returned by the CultureInfo.GetCultures method.

    本主题介绍用于编辑 String 类型的业务对象的区域性代码(区域设置)属性的自定义ASP.NET Web 属性编辑器的实现。属性编辑器控件的下拉列表将显示文化信息.Get 区域性方法返回的区域性。

    Note 注意
    You can also specify predefined values in the Model Editor using the IModelCommonMemberViewItem.PredefinedValues property. This approach is much simpler because it does not require extra coding, but you will be unable to update the values list dynamically in code in this instance.
    您还可以使用 IModelCommonMemberViewItem.预定义值在模型编辑器中指定预定义值。此方法要简单得多,因为它不需要额外的编码,但在这种情况下,您将无法动态更新代码中的值列表。

    The image below shows the resulting Property Editor:

    下图显示了生成的属性编辑器:

    WebPropertyEditorStandardControl

    To implement a Property Editor by inheriting from the ASPxPropertyEditor class, override the following methods (see ASPxPropertyEditor):

    1. Override the CreateEditModeControlCore method to return the ASPxComboBox control using the RenderHelper class' helper method. Subscribe to the control's ValueChanged event to call the Property Editor's EditValueChangedHandler method. This method updates the associated property when the control's value is changed.
    2. Override the SetupControl method to populate the control's dropdown list with items. We use the CultureInfo.GetCultures method to retrieve the cultures installed.

    下图显示了生成的属性编辑器:

    1. 重写"创建编辑模式控制核心"方法,使用"渲染帮助器"类的帮助器方法返回 ASPxComboBox 控件。订阅控件的 ValueChanged 事件以调用属性编辑器的"编辑值更改处理程序"方法。当控件的值发生更改时,此方法将更新关联的属性。
    2. 覆盖 SetupControl 方法,用项填充控件的下拉列表。我们使用文化信息.Get文化方法检索已安装的区域性。

    To specify that the implemented Property Editor can be used for the String type properties, the PropertyEditor attribute is applied (see PropertyEditorAttribute):

    要指定实现的属性编辑器可用于 String 类型属性,将应用属性编辑器属性(请参阅属性编辑器属性):

    using System;
    using System.Globalization;
    using System.Web.UI.WebControls;
    
    using DevExpress.Web;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Web;
    using DevExpress.ExpressApp.Editors;
    using DevExpress.ExpressApp.Web.Editors.ASPx;
    using DevExpress.ExpressApp.Model;
    //...
    [PropertyEditor(typeof(String), false)]
    public class CustomStringEditor : ASPxPropertyEditor {
        ASPxComboBox dropDownControl = null;
        public CustomStringEditor(
        Type objectType, IModelMemberViewItem info) : base(objectType, info) { }
        protected override void SetupControl(WebControl control) {
            if(ViewEditMode == ViewEditMode.Edit) {
                foreach(CultureInfo culture in CultureInfo.GetCultures(
                CultureTypes.InstalledWin32Cultures)) {
                    ((ASPxComboBox)control).Items.Add(culture.EnglishName + "(" + culture.Name + ")");
                }
            }
        }
        protected override WebControl CreateEditModeControlCore() {
            dropDownControl = RenderHelper.CreateASPxComboBox();
            dropDownControl.ValueChanged += new EventHandler(EditValueChangedHandler);
            return dropDownControl;
        }
        public override void BreakLinksToControl(bool unwireEventsOnly) {
            if(dropDownControl != null) {
                dropDownControl.ValueChanged -= new EventHandler(EditValueChangedHandler);
            }
            base.BreakLinksToControl(unwireEventsOnly);
        }
    }

    Apply the ModelDefaultAttribute attribute to use the implemented Property Editor for a business object's CultureCode property:

    应用 ModelDefault属性属性,将实现的属性编辑器用于业务对象的区域性代码属性:

    using DevExpress.ExpressApp.Model;
    //...
    [ModelDefault("PropertyEditorType", "Solution1.Module.Web.CustomStringEditor")]
    public String CultureCode {
       get { return GetPropertyValue<String>(nameof(CultureCode)); }
       set { SetPropertyValue(nameof(CultureCode), value); }
    }

    Here, the Custom attribute specifies the PropertyEditorType property of the Application Model's IModelMember node, that defines the CultureCode property. Alternatively, you can do it using the Model Editor.

    在这里,自定义属性指定应用程序模型的 IModelMember 节点的属性编辑器类型属性,该属性定义区域性代码属性。或者,您可以使用模型编辑器执行此操作。

    Tip 提示
    You can see the code demonstrated here, along with more examples on custom Property Editors in the Feature Center Demo located in the %PUBLIC%DocumentsDevExpress Demos 19.2ComponentseXpressApp FrameworkFeatureCenter folder, by default, or in the Feature Center demo online
    您可以在功能中心演示中查看此处演示的代码,以及有关自定义属性编辑器的更多示例%PUBLIC%DocumentsDevExpress Demos 19.2ComponentseXpressApp FrameworkFeatureCenter folder, by default, or in the Feature Center demo online

    .

  • 相关阅读:
    jquery跨域3
    juery的跨域请求2
    jquery的跨域请求
    synchronized与Lock的区别
    springboot之启动原理解析及源码阅读
    java中Number类理解
    springboot中配置文件application.properties的理解
    restTemplate设置访问超时
    BigDecimal.setScale 处理java小数点
    NIO之FileChannel类的理解和使用
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Supply-Predefined-Values-for-the-String-Property-Editor-Dynamically-ASP-NET.html
Copyright © 2020-2023  润新知