【问题标题】:Sharepoint 2010 sandboxed Webpart ErrorSharepoint 2010 沙盒 Webpart 错误
【发布时间】:2011-10-08 06:56:37
【问题描述】:

我是 sharepoint 的新手,我在 sharepoint 2010 中创建了一个 webpart,我在其中添加了一个 SPGridview,同时部署它正在生成此异常的 webpart

Web 部件错误:部分信任应用程序域中的沙盒代码包装器的 Execute 方法引发了未处理的异常:发生了意外错误。

代码是这样的

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

谁能建议我在这里做错了什么? 感谢致敬 马克

【问题讨论】:

    标签: sharepoint-2010 web-parts


    【解决方案1】:

    我知道了,我使用了沙盒解决方案,并且来自沙盒工作进程的调用仅限于使用多个类和方法。不幸的是,Microsoft.Sharepoint.WebControls 也是类之一。我们仅限于使用 ASP.Net 控件。我将其更改为 Farm Solutions,它运行良好。

    【讨论】:

      猜你喜欢
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 2012-06-20
      • 2011-08-08
      • 2012-11-06
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      相关资源
      最近更新 更多