zoukankan      html  css  js  c++  java
  • sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties

    webpart 是在sharepoint开发过程中,最常用的一种方式。扩展webpart自定义属性边栏字段,可以做到动态给webpart配置参数。如下图所示,在杂项里面,我们看到有三个属性,company,url, city,这个就是我们自定义的3个webpart属性。

    最终我们要实现的效果,就是动态给webpart传递这些参数值。如下图所示:

    1。创建一个sharepoint project 3,5项目,WebpartBarTest,并且添加一个可视化部件WebpartBarProperties,

    如下图所示 :

    2。在页面上添加几个服务器控件,label.

    <table border="1px">
        <tr>
            <td>公司名称:
            </td>
            <td><asp:Label ID="lblCompany" runat="server" Text="" Font-Bold="true"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>所在地:
            </td>
            <td><asp:Label ID="lblUrl" runat="server" Text="" Font-Bold="true"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>公司网址:
            </td>
            <td><asp:Label ID="lblCity" runat="server" Text="" Font-Bold="true"></asp:Label>
            </td>
        </tr>
    </table>

    3.。后台实现代码

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.ComponentModel;

    namespace WebpartBarTest.WebpartBarProperties
    {
        public partial class WebpartBarPropertiesUserControl : UserControl
        {
            /// <summary>
            /// 自定义的webpart属性
            /// </summary>
            public WebpartBarProperties WebPart { get; set; } 
            protected void Page_Load(object sender, EventArgs e)
            {
                this.lblCompany.Text =WebPart.Company;
                this.lblCity.Text =WebPart.City;
                this.lblUrl.Text =WebPart.Url;
            }
           
        }
    }

    using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;

    namespace WebpartBarTest.WebpartBarProperties
    {
        [ToolboxItemAttribute(false)]
        public class WebpartBarProperties : WebPart
        {
            // 当更改可视 Web 部件项目项时,Visual Studio 可能会自动更新此路径。
            private const string _ascxPath = @"~/_CONTROLTEMPLATES/WebpartBarTest/WebpartBarProperties/WebpartBarPropertiesUserControl.ascx";
           
            protected override void CreateChildControls()
            {
                WebpartBarPropertiesUserControl control = Page.LoadControl(_ascxPath) as WebpartBarPropertiesUserControl;
                //添加自定义属性
                if (control != null) 
                { 
                    control.WebPart = this;
                } 
                Controls.Add(control);

            }
            [Personalizable(), WebBrowsable] 
            public String Company { get; set; }
            [Personalizable(), WebBrowsable]
            public String Url { get; set; } 
            [Personalizable(), WebBrowsable]
            public String City { get; set; } 
        }
    }

    4。部署到sharepoint站点上,将这个webpart添加到页面上,并且给我们自定义的3个属性赋值。

    点击确定,这样就完成了我们对webpart自定义属性的扩展。这种方式在sharepoint的开发非常常用。

     程序下载地址:http://download.csdn.net/download/cxx2325938/4898105 

    广州京微信息科技有限公司,微软sharepoint解决方案提供商。

  • 相关阅读:
    二叉树遍历问题、时间空间复杂度、淘汰策略算法、lru数据结构、动态规划贪心算法
    Django--csrf跨站请求伪造、Auth认证模块
    Django--中间件
    Django--Cookie和Session组件
    Django--form表单组件
    安装配置flask环境
    Django--模型层
    Django--路由层、视图层、模版层
    Eclipse SVN文件冲突及不能直接提交情况
    Eclipse开发Web常见异常
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/3131499.html
Copyright © 2011-2022 走看看