zoukankan      html  css  js  c++  java
  • WebPart Complex Property

    下面代码是实现一个Dropdown,同时实现其同步变化。代码如下:

    Complex Property
    using System;
    using System.Runtime.InteropServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.ComponentModel;
    using System.Collections;

    namespace WebPartCollection
    {
    [Guid("cf18e6af-3ab5-4503-8a41-c24ac8d38566")]
    public class ComplexProperty : System.Web.UI.WebControls.WebParts.WebPart
    {
    public ComplexProperty()
    {
    }
    private string _FirstName;
    [Personalizable]
    [WebBrowsable(true)]
    [Category("Name")]
    [WebDisplayName("FirstName")]
    public string FirstName
    {
    get { return _FirstName; }
    set { _FirstName = value; }
    }
    private string _LastName;
    [Personalizable]
    [WebBrowsable(true)]
    [Category("Name")]
    [WebDisplayName("LastName")]
    public string LastName
    {
    get { return _LastName; }
    set { _LastName = value; }
    }

    protected override void Render(HtmlTextWriter writer)
    {
    base.Render(writer);
    }
    public override EditorPartCollection CreateEditorParts()
    {
    ArrayList editorArray = new ArrayList();

    WebPartProperty1EditPart edPart = new WebPartProperty1EditPart();
    edPart.ID = "WebPartProperty1EditPart1";
    editorArray.Add(edPart);

    EditorPartCollection initEditorParts = base.CreateEditorParts();

    EditorPartCollection editorParts = new EditorPartCollection(initEditorParts, editorArray);

    return editorParts;
    }
    protected override void CreateChildControls()
    {

    base.CreateChildControls();

    }
    }

    public class WebPartProperty1EditPart : EditorPart
    {
    private DropDownList _dlValueList;
    private Label _lbCompany;


    //创建下拉列表控件
    protected override void CreateChildControls()
    {
    _lbCompany = new Label();
    _lbCompany.Text = "Company Name: ";

    _dlValueList = new DropDownList();
    _dlValueList.Items.Add("Carat");
    _dlValueList.Items.Add("HR");

    this.Controls.Add(_lbCompany);
    this.Controls.Add(new LiteralControl("<br/>"));
    this.Controls.Add(_dlValueList);
    }
    //将WebPart的值同步到下拉控件
    public override void SyncChanges()
    {
    this.EnsureChildControls();
    ComplexProperty wp = (ComplexProperty)this.WebPartToEdit;
    _dlValueList.SelectedValue = wp.FirstName;
    }
    //将下拉控件选择的值应用到WebPart
    public override bool ApplyChanges()
    {
    this.EnsureChildControls();
    ComplexProperty wp = (ComplexProperty)this.WebPartToEdit;
    wp.FirstName = _dlValueList.SelectedValue;
    return true;
    }
    }

    }



  • 相关阅读:
    VC++6.0调用外部dll
    VC++6.0配置Opencv
    Qt 解决中文乱码问题
    Qt Widget控件设置布局后,内部控件大小发生变化
    QtDesigner 控件自适应窗体的方法
    QtSoap调用WebService服务
    QLabel自定义类实现点击效果以及鼠标掠过字体的颜色变化效果
    VS2017中工具箱控件是灰色(不可用)解决方法
    OpenCV(3.4.1) Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:uildmaster_winpack-build-win64-vc15opencvmoduleshighguisrcwindow.cpp, line 356
    OpenCV之错误集锦-1
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2198968.html
Copyright © 2011-2022 走看看