Create a simple Web Part widget in SharePoint

Source: Internet
Author: User
Tags visual studio

Standard Web Parts can sometimes be very powerful and can perform many functions. This article focuses on using visual Studio to create a simple Web Part.

1. Open vs, click on file----new item.

2. Select a blank SharePoint project. Name Smallvillewebpartproject, click OK. Select Deployment as a farm solution.

3. Right-click the project to add a new item.

4. Select the Web Part.

5. Name Customerinformation, click Add.

6. Right-click the new Web Part project, select Add Class, Name CustomerData, click OK.

7. In the new class, modify the code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
    
Namespace Smallvillewebpartproject.customerinformation
{
class customerdata
{public
string companyName {get; set;}
public string ContactName {get; set;}
public string Contactemail {get; set;}
public string Companyfy08sales {get; set;}
public string Companyfy09sales {get; set;}}}

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/

8. Right-click the core Web Part and select View Code (or double-click the Web Part).

9. Modify the code as follows:

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.Collections.Generic; namespace Smallvillewebpartproject.customerinformation {[ToolboxItemAttribute (false)] public class
Customerinformation:webpart {DataGrid mycustomers = new DataGrid ();
    
list<customerdata> mycustomerdatalist = new list<customerdata> ();
protected override void OnPreRender (EventArgs e) {customerdata cust1 = new CustomerData ();
CustomerData cust2 = new CustomerData ();
CustomerData cust3 = new CustomerData ();
CustomerData Cust4 = new CustomerData ();
Cust1.companyname = "Fabrikam";
Cust1.contactname = "Harvey Kitell";
Cust1.contactemail = "mrpink@fabrikam.com";
Cust1.companyfy08sales = "$530,002.00";
Cust1.companyfy09sales = "$650,102.00";
Mycustomerdatalist.add (CUST1);
Cust2.companyname = "Contoso"; Cust2.contaCtname = "Ahmed Kroll";
Cust2.contactemail = "ahemd@contoso.com";
Cust2.companyfy08sales = "$1,577,044.00";
Cust2.companyfy09sales = "$1,653,112.00";
Mycustomerdatalist.add (CUST2);
Cust3.companyname = "ACME";
Cust3.contactname = "Jansen Terrace";
Cust3.contactemail = "jansen@acme.com";
Cust3.companyfy08sales = "$3,270,000.00";
Cust3.companyfy09sales = "$2,953,100.00";
Mycustomerdatalist.add (CUST3);
Cust4.companyname = "Wingtip";
Cust4.contactname = "Hally Cantrall";
Cust4.contactemail = "hally@wingtip.com";
Cust4.companyfy08sales = "$578,982.00";
Cust4.companyfy09sales = "$620,100.00";
Mycustomerdatalist.add (CUST4);
Mycustomers.datasource = mycustomerdatalist;
Mycustomers.databind (); } protected override void CreateChildControls () {this.
Controls.Add (mycustomers); }
}
}

10. Then double-click Customerinformation.webpart to modify its caption and description properties.

<?xml version= "1.0" encoding= "Utf-8"?>
<webParts>
<webpart xmlns= "http:// Schemas.microsoft.com/webpart/v3 ">
<metaData>
<type name=" SmallvilleWebPartProject.CustomerInformation.CustomerInformation, $SharePoint. project.assemblyfullname$ "  / >
<importErrorMessage> $Resources:core,importerrormessage;</importerrormessage>
</ metadata>
<data>
<properties>
<property name= "Title" type= "string" >customer Info Web part</property>
<property name= "Description" type= "string" >a Web part that displays customer information</property>
</properties>
</data>
</webPart>
</ Webparts>

11. Now you can deploy this standard Web Part. Click Build----Deploy the solution.

12. Add on the page. Click the site action--edit page--to add a Web Part.

13. Navigate to Custom category and select Customer Info Web part. Click Add.

Author: csdn Blog Zhang Shihui

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.