I have created a gallery page type and a Image page type. The gallery type contains many image types.
I have successfully rendered all relevant information on the gallery page except the image itself. I have the url to the image page and the acual source to the picture. In my mind I want to use a href and a img to get this working, but how do I combinate episerver:properties and asp:Image?
I have a SearchDataSource and a DataList to render my information.
And I want something like this inside the datalist:
<img id="aImage" src="" runat="server" / >
But how do I add the source to the img from a episerver:property?
not sure of what you mean but you can ad the url to an image from codebehind via CurrentPage["propertyname.."].linkurl have a look in our SDK at http://sdk.episerver.com for our build in properties and how they work.
You could use front end as well with somthing like this <%#Container.CurrentPage["ImageLink"].LinkURL%>);
This did the trick:
<asp:DataList ID="datalist1" DataSourceID="srcDS" runat="server"> <HeaderTemplate> <table border="0"> </HeaderTemplate> <ItemTemplate> <tr> <a href=' <%# ((EPiServer.Core.PageData)Container.DataItem).LinkURL %>'> <asp:Image ImageUrl='<%# ((EPiServer.Core.PageData)Container.DataItem).Property["Image"] %>' Width="90" Height="100" ID="image" runat="server" /> </a> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList>
I don't know why, but when I added <%# Container... as you suggested Eric I received the following message:
'System.Web.UI.WebControls.DataListItem' does not contain a definition for 'CurrentPage'
Does it mean that I can't use the CurrentPage in a datalist?
Yes exactly you are not able to use currenpage object in a asp.net list like listview or datalist. They have something called DataItem instead and you will have to cast that object to a EPiserver PageData object instead, just like you did! Sorry for the missunderstanding..
If i where you i would look into using listview instead of datalist beacause you are able to design the html much more in the listviewcontrol.... maybe you already know this but just in case..
I understand, thanks.
I have only read about the ListView, it is a .net 3.5 controll right?
I will take a look at it. It seems to fit my solution in a good way.
Thanks again, /Magnus
Yes it is new in 3.5. We are using it a lot on our pages for exampel on this forum and also in our new relate+-package. But a sugestion if your about to work with paging is to actually create your own datapager instead of using the one that comes with listview or at least tweak a little bit.
Here are some pages about listview: