Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Get Next Item in Random Document webpart View modes: 
User avatar
Member
Member
gaurav.agrawal-octalsoftware - 4/8/2011 2:37:56 AM
   
Get Next Item in Random Document webpart
Hi,

I am using a random document webpart for showing images in a div and in the div there are 2 link buttons named "Prev", Next". i want to show next random image on the 'Next" button click and Previous random image on the "Prev" button click.

Can anyone give me some idea about this......

Thanks,
Gaurav Agrawal

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/12/2011 5:15:32 PM
   
RE:Get Next Item in Random Document webpart
Hi,

You basically need to select multiple documents and use paging with page size equal to one, so that only one document is displayed at a time.

Since default Random document webpart doesn't have pager control properties, you will need to modify its code to allow them or directly set them in codebehind. I would suggest to clone the default webpart first before making changes.

In the cloned webpart code, (default one is at \CMSWebParts\Viewers\Documents\randomdocument.ascx.cs), in SetupControl() method you can set the properties of the repeater's pager control like this:

 
...
repElem.Columns = Columns

// modification begin
// paging when more documents selected
repElem.EnablePaging = true;
repElem.PageSize = 1;
repElem.PagerControl.PagerPosition = CMS.Controls.PagingPlaceTypeEnum.Bottom;
repElem.PagerControl.ShowPageNumbers = false;
repElem.PagerControl.ShowFirstLast = false;
repElem.PagerControl.PagingMode = CMS.Controls.PagingModeTypeEnum.PostBack;
...


More details about this can be found at http://devnet.kentico.com/docs/controls/datapager_overview.htm

As suggested, it would be better to use UniPager control. This example with DataPager is just for illustration, but works fine too..

Then in the webpart properties, please define "Random N" property, which "sets the number of random documents that should be selected, by default one random document is selected." You can specify any number, if there is not as many documents, it won't matter, however it's not wise to select any high number. Otherwise some better (more scalable) approach should be used.

Hope this helps.

--Zdenek