Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Dynamically Load Media Library Path based on DropDownList Selection View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
spengelly - 11/9/2010 9:32:40 AM
   
Dynamically Load Media Library Path based on DropDownList Selection
I am trying to embed the media library in an ascx control where I want to dynamically change the Media Library Path based on a value selected from dropdownlist.

The initial load of the media library displays correctly. When I try to reload the media library data based on a selected value in the dropown which corresponds to another media library path it doesn’t release the original dataset and load the new one.

I've tried the mediagallery.ReloadData(); but I can't seem to get it to work. I'm not sure if I am calling this method in the wrong place. I've tried in SetUpControl(), on Page_Load, OnContentLoaded().

I thought I should be able to do this based on this Knowledgebase article
http://devnet.kentico.com/Knowledge-Base/Media-Libraries/to-use-Media-gallery-web-part-on-ASPX-page-templat.aspx

Any thoughts or help would be greatly appreciated. Thanks!

Sarah

User avatar
Member
Member
kentico_michal - 11/12/2010 5:57:11 AM
   
RE:Dynamically Load Media Library Path based on DropDownList Selection
Hi,

Well, I would recommend you to use different approach based on creating custom web part ( custom web part ).
It could contain standard Media gallery web part and drop-down list.

Please take a look at following definition of this components:

<%@ Register Src="~/CMSWebParts/MediaLibrary/MediaGallery.ascx" TagName="MediaGallery" TagPrefix="uc1" %>

<uc1:MediaGallery ID="cntMediaGallery" runat="server"
HideFolderTree="true" TransformationName="Community.Transformations.MediaLibrary"
SelectedItemTransformation="Community.Transformations.MediaLibrarySelectedItem"
SeparatorTransformation="Community.Transformations.MediaLibraryItemSeparator"
HeaderTransformation="Community.Transformations.MediaLibraryHeader" FooterTransformation="Community.Transformations.MediaLibraryFooter"
FilterMethod="0" FileIDQueryStringKey="fileid" PathQueryStringKey="path" SortQueryStringKey="sort"
EnableViewState="false" />

<asp:DropDownList runat="server" id="ddl1" OnSelectedIndexChanged="onChange" AutoPostBack="true">
<asp:ListItem Text="czechcities" value="czechcities" ></asp:ListItem>
<asp:ListItem Text="czechnature" value="czechnature" Selected="True"></asp:ListItem>
</asp:DropDownList>



You may use following code in code behind of this web part:

public partial class CMSWebParts_MediaLibrary_CustomMedia : CMSAbstractWebPart
{
protected void Page_Load(object sender, EventArgs e)
{
cntMediaGallery.MediaLibraryName = ddl1.SelectedValue;
cntMediaGallery.ReloadData();
}

protected void onChange(object sender, EventArgs e)
{
cntMediaGallery.MediaLibraryName = ddl1.SelectedValue;
cntMediaGallery.ReloadData();
}
}


This way you achieve that Media gallery web part reload depending on current selected value in drop-down list.

Best regards,
Michal Legen