Sharepoint 2010 sandboxed Webpart Error
i am new to sharepoint and i have created a webpart in sharepoint 2010 in which i have added a SPGridview while deploying the webpart it is generating this exception
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.
the code is like this
using System;
using System.ComponentModel;
usi开发者_StackOverflow社区ng 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;
}
}
}
Can any one suggest me what i am doing wrong here ? Thanks and Regards Mac
Well i got it i have used sanboxed solutions and Calls from Sandboxed worker process are restricted to use several classes and methods. Unfortunately, Microsoft.Sharepoint.WebControls is also one of the classes. we are limited to using ASP.Net controls only. i changed it to Farm Solutions and it is working fine.
精彩评论