Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Webpart / Widget Help View modes: 
User avatar
Member
Member
lwhittemore-emh - 3/15/2012 7:48:51 AM
   
Webpart / Widget Help
I am trying to create a widget to place on the home page of a site that gives the user the ability to select a document and have the data from that document displayed on the home page through a transformation.

I thought I could use a repeater but was not able to get it to work. I have looked through all the webparts and cannot find one that lets me select a single document.

I am probably overlooking the obvious.

Thanks
Lawrence

User avatar
Member
Member
kentico_michal - 3/20/2012 7:24:34 AM
   
RE:Webpart / Widget Help
Hello,

You can add a drop down list and the CMSRepeater controls to the web part:
<asp:DropDownList runat="server" ID="ddl" AutoPostBack="true" OnSelectedIndexChanged="OnSelectedIndexChanged" ></asp:DropDownList>
<cms:CMSRepeater runat="server" ID="rep" TransformationName="cms.news.default" HideControlForZeroRows="true" ></cms:CMSRepeater>

Within the Page_Load method, you can bind the drop-down list control with data set as shown here:

TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
DataSet ds = tree.SelectNodes(CMSContext.CurrentSiteName, "/%", "en-us", false, "cms.news");

if (!DataHelper.DataSourceIsEmpty(ds))
{
ddl.DataSource = ds;
ddl.DataTextField = "DocumentName";
ddl.DataValueField = "DocumentID";
ddl.DataBind();
}

The drop down list control provides the OnSelectedIndexChanged handler in which you can access the selected DocumentID, get the TreeNode object and bind the CMSRepeater control:
protected void OnSelectedIndexChanged (object sender, EventArgs e)
{
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
TreeNode node = DocumentHelper.GetDocument(ValidationHelper.GetInteger(ddl.SelectedValue, 0), tree);
rep.DataSource = node.GetDataSet();
rep.DataBind();
}

Anyway, you should also consider caching returned data set of documents to improve performance: Caching API examples.

Moreover, more information about developing web parts, can be found here: Developing web parts

I hope this will help you.

Best regards,
Michal Legen