2

Using VS 2010 i've created BCS model for external MS SQL source, deployed it with success, then created external list - it works perfect.

Now my task is - create visual web part in VS2010 and place sharepoint:ListView in it to display external list. See code for CreateChildControls() method:

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

        Microsoft.SharePoint.WebControls.ListView view = new Microsoft.SharePoint.WebControls.ListView();
        SPList list = SPContext.Current.Web.Lists["Doc"];
        view.ListId = list.ID.ToString();
        view.ViewId = list.Views["ReadListByCategory"].ID.ToString();

        Controls.Add(view);
    }

After adding web part on page i got error:

!--Unable to display web part--.

There is no problem with other sharepoint lists. Only with external list.

Does anyone have experience in creating Web Part with External list in it?

1

Try using XsltListViewWebPart instead of ListView

Following code should render the External List

 protected override void CreateChildControls()    { 
        Microsoft.SharePoint.WebPartPages.XsltListViewWebPart view = new Microsoft.SharePoint.WebPartPages.XsltListViewWebPart();
        SPList list = SPContext.Current.Web.Lists["Doc"];
        view.ListId = list.ID;
        view.ViewGuid = list.Views["ReadListByCategory"].ID.ToString();
        Controls.Add(view);    
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy