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

The Situation

I have a SharePoint 2007 List with a Calendar View. I need to display this View in a custom ASPX page as marked 'Place code here to view SharePoint View of List X' in the following code.

How do I go about it?

The Code

<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" %>
<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderAdditionalPageHead">

</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderMain">

// Place code here to view SharePoint View of List X

</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea">
    The Page Title in Title Area    
</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="PlaceHolderPageTitle">
    The Page Title
</asp:Content>
share|improve this question
add comment

3 Answers 3

What I would try and do is to create the List View how you want it to appear onto a web part page, then open that web part page in SharePoint Designer. You should be able to see the ListViewWebPart tag in there - copy it out and dump it into the PlaceHolderMain content tag.

share|improve this answer
    
But it seems to have an error saying about tag issue. I searched the internet and it also mention need to create a web.config file. Appreciate if you can provide more details / guidance on this. –  Larry Morries Oct 20 '11 at 6:59
    
What reference did you read about creating a web.config file? That seems unnecessary. –  James Love Oct 20 '11 at 7:21
add comment

Another option would be to add a web part zone and drop in the list web part or a data view web part.

share|improve this answer
add comment

Here's an example I've ripped out of a more complex page from a rather old project. I'm not sure if it'll work without tweaking because I don't have a SharePoint 2007 virtual machine at my disposal currently, but it should get you started.

Add this onto your page head:

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Import Namespace="System" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.UI" %> <%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Web.UI.HtmlControls" %>

<%@ Import Namespace="Microsoft.SharePoint" %> <%@ Import Namespace="Microsoft.SharePoint.Utilities" %> <%@ Import Namespace="Microsoft.SharePoint.WebControls" %>

Put this somewhere at the top of the page:

<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{
    string listID = "PlaceYourListGuidHere";
    string viewID = "PlaceYourViewGuidHere";

    ListView renderView = new ListView();
    renderView.ListId = listID;
    renderView.ViewId = viewID;

    this.Page.Controls.FindControl("PlaceHolderMain").Controls.FindControl("idRenderView").Controls.Add(renderView);

    StringWriter stringWriter = new StringWriter();

    using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
    {
        renderView.RenderControl(writer);
    }
}

</script>

And this inside your placeholder:

<asp:PlaceHolder id="idRenderView" runat="server" />

Update: Cleaned up the code a little bit.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.