sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties
办公教程导读
互联网集市收集整理了【sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties】办公软件教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2710字,纯文字阅读大概需要4分钟。
办公教程内容图文
![sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties](/upload/InfoBanner/jiaochengoffice/89/45029ffcc9a0487391ba579ce6f0a89b.jpg)
webpart 是在sharepoint开发过程中,最常用的一种方式。扩展webpart自定义属性边栏字段,可以做到动态给webpart配置参数。如下图所示,在杂项里面,我们看到有三个属性,company,url, city,这个就是我们自定义的3个webpart属性。
![sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties](/upload/getfiles/102/2023/5/30/20230530102503353.gif)
最终我们要实现的效果,就是动态给webpart传递这些参数值。如下图所示:
![sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties](/upload/getfiles/102/2023/5/30/20230530102503475.gif)
1。创建一个sharepoint project 3,5项目,WebpartBarTest,并且添加一个可视化部件WebpartBarProperties,
如下图所示 :
![sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties](/upload/getfiles/102/2023/5/30/20230530102503597.gif)
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个属性赋值。
![sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties](/upload/getfiles/102/2023/5/30/20230530102503719.gif)
点击确定,这样就完成了我们对webpart自定义属性的扩展。这种方式在sharepoint的开发非常常用。
![sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties](/upload/getfiles/102/2023/5/30/20230530102503839.gif)
办公教程总结
以上是互联网集市为您收集整理的【sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties】办公软件教程的全部内容,希望文章能够帮你了解办公软件教程sharepoint 2010 如何扩展webpart自定义属性边栏字段 custom webpart properties。 如果觉得互联网集市办公软件教程内容还不错,欢迎将互联网集市网站推荐给好友。
办公教程备注
版权声明:本文内容由互联网用户贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
办公教程手机端
扫描二维码推送至手机访问。