Skip to main content
added 175 characters in body
Source Link
Ziba Leah
  • 2k
  • 11
  • 48
  • 73

Don't know really HOWIt's not possible to extend a ListView Webpart, butso i create a base webpart and inserted in this code works"container" a ListView WebPart..

This get parameters directly from the url / parameters and select the list this way!

Take a look =)

public partial class VisualWebPart1UserControl : UserControl
{
    private Microsoft.SharePoint.WebPartPages.ListViewWebPart myListView;
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        SPSite oSiteCollection = SPContext.Current.Site;
        string listName = Context.Request.Param["List"];
        SPWeb oWebSite = SPContext.Current.Web;
        myListView = new Microsoft.SharePoint.WebPartPages.ListViewWebPart();
        myListView.Visible = true;
        myListView.EnableViewState = true;
        SPList list = oWebSite.Lists[listName];

        myListView.ListName = list.ID.ToString("B").ToUpperInvariant();
        myListView.TitleUrl = list.DefaultViewUrl;
        myListView.WebId = list.ParentWeb.ID;

        myListView.ListId = (System.Guid)list.ID;
        myListView.ViewGuid = list.DefaultView.ID.ToString("B").ToUpperInvariant();

        myListView.HelpMode = WebPartHelpMode.Modeless;

        Controls.Add(myListView);
    }

Hope this will help someone =)

Don't know really HOW, but this code works!

Take a look =)

public partial class VisualWebPart1UserControl : UserControl
{
    private Microsoft.SharePoint.WebPartPages.ListViewWebPart myListView;
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        SPSite oSiteCollection = SPContext.Current.Site;
        string listName = Context.Request.Param["List"];
        SPWeb oWebSite = SPContext.Current.Web;
        myListView = new Microsoft.SharePoint.WebPartPages.ListViewWebPart();
        myListView.Visible = true;
        myListView.EnableViewState = true;
        SPList list = oWebSite.Lists[listName];

        myListView.ListName = list.ID.ToString("B").ToUpperInvariant();
        myListView.TitleUrl = list.DefaultViewUrl;
        myListView.WebId = list.ParentWeb.ID;

        myListView.ListId = (System.Guid)list.ID;
        myListView.ViewGuid = list.DefaultView.ID.ToString("B").ToUpperInvariant();

        myListView.HelpMode = WebPartHelpMode.Modeless;

        Controls.Add(myListView);
    }

Hope this will help someone =)

It's not possible to extend a ListView Webpart, so i create a base webpart and inserted in this "container" a ListView WebPart..

This get parameters directly from the url / parameters and select the list this way!

Take a look =)

public partial class VisualWebPart1UserControl : UserControl
{
    private Microsoft.SharePoint.WebPartPages.ListViewWebPart myListView;
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        SPSite oSiteCollection = SPContext.Current.Site;
        string listName = Context.Request.Param["List"];
        SPWeb oWebSite = SPContext.Current.Web;
        myListView = new Microsoft.SharePoint.WebPartPages.ListViewWebPart();
        myListView.Visible = true;
        myListView.EnableViewState = true;
        SPList list = oWebSite.Lists[listName];

        myListView.ListName = list.ID.ToString("B").ToUpperInvariant();
        myListView.TitleUrl = list.DefaultViewUrl;
        myListView.WebId = list.ParentWeb.ID;

        myListView.ListId = (System.Guid)list.ID;
        myListView.ViewGuid = list.DefaultView.ID.ToString("B").ToUpperInvariant();

        myListView.HelpMode = WebPartHelpMode.Modeless;

        Controls.Add(myListView);
    }

Hope this will help someone =)

Source Link
Ziba Leah
  • 2k
  • 11
  • 48
  • 73

Don't know really HOW, but this code works!

Take a look =)

public partial class VisualWebPart1UserControl : UserControl
{
    private Microsoft.SharePoint.WebPartPages.ListViewWebPart myListView;
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        SPSite oSiteCollection = SPContext.Current.Site;
        string listName = Context.Request.Param["List"];
        SPWeb oWebSite = SPContext.Current.Web;
        myListView = new Microsoft.SharePoint.WebPartPages.ListViewWebPart();
        myListView.Visible = true;
        myListView.EnableViewState = true;
        SPList list = oWebSite.Lists[listName];

        myListView.ListName = list.ID.ToString("B").ToUpperInvariant();
        myListView.TitleUrl = list.DefaultViewUrl;
        myListView.WebId = list.ParentWeb.ID;

        myListView.ListId = (System.Guid)list.ID;
        myListView.ViewGuid = list.DefaultView.ID.ToString("B").ToUpperInvariant();

        myListView.HelpMode = WebPartHelpMode.Modeless;

        Controls.Add(myListView);
    }

Hope this will help someone =)