I'd like to extend the ListView WebPart so that it can read data from the url... I tried to extend a ListView WebPart but compiler told me it is sealed and so I cannot extend.. Then I tried to insert a ListView WebPart INSIDE my custom webpart but this way doesn't work...
How could I do?
This is my code!
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Web.UI.HtmlControls;
namespace UrlParametrizedListViewWebPart.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
private Microsoft.SharePoint.WebPartPages.ListViewWebPart myListView;
protected override void CreateChildControls()
{
base.CreateChildControls();
SPSite oSiteCollection = SPContext.Current.Site
string listName = "docs";
SPWeb oWebSite = SPContext.Current.Web
myListView = new Microsoft.SharePoint.WebPartPages.ListViewWebPart();
myListView.Visible = true;
myListView.EnableViewState = true;
SPList list = oWebSite.Lists[listName];
myListView.ListId = (System.Guid)list.ID;
myListView.ViewGuid = list.DefaultView.IT.ToString();
Controls.Add(myListView);
}
}
}
Result of this code:
< !-- #RENDER FAILED -->
I tried another way: add all the controls of the "son webpart" and not the webpart.. It seems working! I think is not the right way to do that.. So if everybody has some suggestion... =)
namespace UrlParametrizedListViewWebPart.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
private Microsoft.SharePoint.WebPartPages.ListViewWebPart myListView;
protected override void CreateChildControls()
{
base.CreateChildControls();
SPSite oSiteCollection = SPContext.Current.Site
string listName = "docs";
SPWeb oWebSite = SPContext.Current.Web
myListView = new Microsoft.SharePoint.WebPartPages.ListViewWebPart();
myListView.Visible = true;
myListView.EnableViewState = true;
SPList list = oWebSite.Lists[listName];
myListView.ListId = (System.Guid)list.ID;
myListView.ViewGuid = list.DefaultView.IT.ToString();
//ADDS MANUALLY THE WP CONTROLS:
foreach(Control c in myListView.Controls)
{
this.Controls.Add(c);
}
}
}
}