Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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);    
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.