2011-07-19 115 views
0

我新的SharePoint和我已經創造了2010 SharePoint中的web部件,其中在部署Web部件是產生此異常SharePoint 2010的沙盒的WebPart錯誤

Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.

的代碼是這樣的我加了SPGridview

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.Data; 

namespace DemoProject.HelloWorldWebPart 
{ 
    [ToolboxItemAttribute(false)] 
    public class HelloWorldWebPart : WebPart 
    { 
     protected override void CreateChildControls() 
     { 
      //Label lblHelloWorld = new Label(); 
      //lblHelloWorld.Text = "Hello World"; 
      //this.Controls.Add(lblHelloWorld); 
      //const string DATASOURCEID = "gridDS"; 

      ObjectDataSource gridDS = new ObjectDataSource(); 
      gridDS.ID = "gridDS"; 
      gridDS.SelectMethod = "SelectData"; 
      gridDS.TypeName = this.GetType().AssemblyQualifiedName; 
      gridDS.ObjectCreating += new ObjectDataSourceObjectEventHandler(gridDS_ObjectCreating); 
      this.Controls.Add(gridDS); 

      // Instantiating Sharepoint GridView object and assigning properties to it 
      SPGridView spgvStudentList = new SPGridView(); 
      spgvStudentList.ID = "spgvStudentList"; 
      spgvStudentList.DataSourceID = gridDS.ID; 
      spgvStudentList.AutoGenerateColumns = false; 
      spgvStudentList.AllowPaging = true; 
      spgvStudentList.PageSize = 5; 
      spgvStudentList.AllowSorting = true; 
      this.Controls.Add(spgvStudentList); 

      SPGridViewPager pager = new SPGridViewPager(); 
      pager.GridViewId = spgvStudentList.ID; 
      this.Controls.Add(pager); 
     } 
     public DataTable SelectData() 
     { 
      // Creating a datasource object for databinding the sharepoint gridview 
      DataTable dataSource = new DataTable(); 

      dataSource.Columns.Add("ID"); 
      dataSource.Columns.Add("Name"); 
      dataSource.Columns.Add("Region"); 
      dataSource.Columns.Add("Total Sales"); 

      dataSource.Rows.Add(1, "J. Smith", "Europe", 10000); 
      dataSource.Rows.Add(2, "J. Smith", "North America", 15000); 
      dataSource.Rows.Add(3, "J. Smith", "Asia", 5000); 
      dataSource.Rows.Add(4, "S. Jones", "Europe", 7000); 
      dataSource.Rows.Add(5, "S. Jones", "North America", 30000); 
      dataSource.Rows.Add(6, "S. Jones", "Asia", 8700); 
      dataSource.Rows.Add(7, "W. Nguyen", "Europe", 3000); 
      dataSource.Rows.Add(8, "W. Nguyen", "North America", 50000); 
      dataSource.Rows.Add(9, "W. Nguyen", "Asia", 25000); 

      return dataSource; 
     } 

     private void gridDS_ObjectCreating(object sender, ObjectDataSourceEventArgs e) 
     { 
      e.ObjectInstance = this; 
     } 
    } 
} 

任何人都可以告訴我我在做什麼錯在這裏? 感謝和問候 Mac

回答

0

嗯,我得到它我已經使用sanboxed解決方案和來自沙盒工作進程的調用被限制使用幾個類和方法。不幸的是,Microsoft.Sharepoint.WebControls也是其中的一個類。我們僅限於使用ASP.Net控件。我將其更改爲農場解決方案,它工作正常。