2011-07-19 7 views
0

je suis nouveau à sharepoint et j'ai créé un webpart dans sharepoint 2010 dans lequel j'ai ajouté un SPGridview tout en déployant le webpart il génère cette exceptionSharepoint 2010 sandbox Webpart Erreur

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.

le code est comme ça

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; 
     } 
    } 
} 

Quelqu'un peut-il me suggérer ce que je fais mal ici? Merci et salutations Mac

Répondre

0

Eh bien je l'ai eu, je l'ai utilisé des solutions sanboxed et appels de processus de travail en sandbox sont limitées à utiliser plusieurs classes et méthodes. Malheureusement, Microsoft.Sharepoint.WebControls est également l'une des classes. nous sommes limités à l'utilisation des contrôles ASP.Net uniquement. Je l'ai changé pour Farm Solutions et ça marche bien.

Questions connexes