Frage

Ich habe einen BCS-Dienst erstellt und eine externe Liste von dem BCS-Inhaltstyp erstellt. Ich habe dann versucht, eine SPGridView Steuerung zu einem webpart hinzuzufügen. Ich erhalte eine Ausnahme, sobald ich meinen SPGridview des DataBind() Methode aufrufe, hier ist das, was der Code wie folgt aussieht:

namespace BCSService.CustomWebPart
{
    [ToolboxItemAttribute(false)]
    public class CustomWebPart : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/BCSShims/CustomWorkEstimateWebPart/CustomWorkEstimateWebPartUserControl.ascx";
        private SPGridView gv;
        private SPDataSource spdata;
        private SPSite site;
        private SPWeb web;
        private SPList we_list;


    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        Control control = Page.LoadControl(_ascxPath);
        Controls.Add(control);

        this.site = SPContext.Current.Site;
        this.web = this.site.OpenWeb();
        this.we_list = this.web.Lists["BCSList"];

        this.spdata = new SPDataSource();
        Controls.Add(this.spdata);

        this.gv = new SPGridView();
        this.gv.AutoGenerateColumns = false;

        Controls.Add(this.gv);            
    }

    protected void BindColumns()
    {
        this.spdata.DataSourceMode = SPDataSourceMode.List;
        this.spdata.List = this.we_list;
        this.spdata.UseInternalName = true;
        this.spdata.DataBind();

        this.gv.AllowSorting = false;
        this.gv.PageSize = 200;
        this.gv.DataSource = this.spdata;

        Dictionary<string, string> listFields = new Dictionary<string, string>();
        listFields.Add("CompanyName", "Company Name");
        listFields.Add("ContactDetails", "Contact Details");
        listFields.Add("ProjectDescription", "Description");

        foreach (var row in listFields)
        {
            SPBoundField boundField = new SPBoundField();
            boundField.HeaderText = row.Value;
            boundField.DataField = row.Key;
            this.gv.Columns.Add(boundField);
        }
    }


    protected override void RenderContents(HtmlTextWriter writer)
    {

        if (!Page.IsPostBack)
        {
            this.BindColumns();
            this.gv.DataBind();
        }

        this.gv.RenderControl(writer);
    }
}

}

Die DataBind() Methode wird die folgende Ausnahme werfen:

Object reference not set to an instance of an object.
   at Microsoft.SharePoint.WebControls.SPDataSourceViewResultItem.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
   at System.ComponentModel.TypeDescriptor.MergedTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
   at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes)
   at System.ComponentModel.TypeDescriptor.GetProperties(Object component)
   at Microsoft.SharePoint.WebControls.SPBoundField.DataBindingEventHandler(Object sender, EventArgs e)
   at System.Web.UI.Control.OnDataBinding(EventArgs e)
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
   at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at Microsoft.SharePoint.WebControls.SPGridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at BCSService.CustomWebPart.CustomWorkEstimateWebPart.RenderContents(HtmlTextWriter writer)

Ich habe festgestellt, dass this.we_list nicht leer ist (in Visual locals Registerkarte Studio-Debugger, kann ich sehen, this.we_list.Items.Count bis 99 gesetzt ist, obwohl this.we_list.ItemCount auf 0 gesetzt ist.)

Auch das scheint alles in Ordnung gegen nicht-externe Listen zu arbeiten, aber ich sehe nichts in der Dokumentation über externe Listen nicht in SPGridView oder SPDataSource unterstützt wird, und die Ausnahme nicht die Rede von externen Listen nicht unterstützt. Hat jemand laufen in dieses Problem?

War es hilfreich?

Lösung

Dies scheint einen möglichen Sharepoint Server 2010 Fehler zu sein (ich bin mit Sharepoint Server 2010 Enterprise Edition). Letztlich gelöst, ich habe das Problem, indem ein to_datatable () Umwandlungsverfahren meiner BCS-Serviceeinheit fügte hinzu, dass verwendet einfach die Statis Readlist () -Methode, sammelt seine Ausgabe und fügt die Daten in ein Datatable-Objekt.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top