I have a custom list with two fields.
Title that holds integer value and Image(that holds the Url of the image.
In my pagelayout.aspx page, I have an event Page_load. Inside it, I want to display the images from that SPList randomly on each page refresh.
if (pubPage != null && pubPage.Layout.Title == "ABCHome Page Layout")
{
//Get the list
SPList HomepageImage = currentWeb.Lists["Homepage Images"];
//Get the list items
SPListItemCollection collListItems = HomepageImage.Items;
//Select one of the list items
Random random = new Random();
//bannerImage = string.Format("<img src=\"{0}/{1}\">", HomepageImage.Items[random.Next(0, collListitems.Count - 1)].Url);
break;
}
//testImage is the Image control defined inside Placeholder Main.
testImage.ImageUrl = bannerImage;
--- Its not working. Can you please let me know a proper way to complete my task?
Thanks.