Custom attributes Expand your Web Part widget with additional options and settings. This article explains how to create a simple custom Web Part widget property using Visual Studio.
1. Open Visual Studio and click on the file--new project--blank SharePoint Project Customwpproperties. Deployed as a farm solution.
2. Right-click the item Add New Item Web Part widget wppropertyexample, click Add.
3. Right-click WPPropertyExample.cs and click View Code.
4. Add the code, and finally it's like this:
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;
Using System.Xml.Serialization;
Namespace Customwpproperties.wppropertyexample
{public
class Wppropertyexample:webpart
{
Label Lbltitle = new label ();
Public enum sharepointlists
{
Stats, products
,
Customers,
}
protected Sharepointlists listoflist;
[Personalizable (Personalizationscope.user),
WebBrowsable,
webdisplayname ("Available Lists"),
webdescription ("Available Lists in SharePoint Site.")]
Public sharepointlists mysticks
{get
{return listoflist;}
set {listoflist = value;}
}
protected override void CreateChildControls ()
{
Lbltitle.text = "Web part with";
This. Controls.Add (Lbltitle);}}
5. Click Build--Deploy the solution.
6. On the SharePoint site, click the Site Action-edit page-Add the Web Part, select Wppropertyexample in the custom class, and click Add.
7. Edit this Web Part, as you can see in the Properties pane:
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/