SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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();


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

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();
share|improve this answer

Your Answer


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