Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

in a GridView I have an image field, it's a hyperlink like below:

ASP.NET
<asp:TemplateField HeaderText="Images">                                         <ItemTemplate>
<asp:HyperLink runat="server" ID="filesImages" NavigateUrl='<%#string.Format("http://abc.com/ic_images/commonfiles/ICImages/{0}",Eval("FILES")) %>' Font-Underline="true" Target="_blank"><%#Eval("FILES") %></asp:HyperLink>
 </ItemTemplate>
</asp:TemplateField>


That will display the image in a big size in new window. The code is working very well, BUT the problem is in the table I have more than one image for the same record separated by (|), for example in FILES field I could have image.jpg OR image1.jpg|image2.jpg|image3.jpg ... etc
Is there a way to display those images the way they are in the table but when click will display different image for each one separated?

I hope i well explained my point, please advise!

Thanks in advance
Samira
Posted

1 solution

Something like this should work:
HTML
<asp:TemplateField HeaderText="Images">
<ItemTemplate>
    <asp:ListView runat="server" DataSource='<%# Eval("FILES", "{0}").Split(&apos;|&apos;) %>'>
    <LayoutTemplate>
        <ul>
            <li id="itemPlaceholder" runat="server" />
        </ul>
    </LayoutTemplate>
    <ItemTemplate>
        <li><asp:HyperLink runat="server"
            NavigateUrl='<%# string.Format("http://abc.com/ic_images/commonfiles/ICImages/{0}", Container.DataItem) %>'
            Text='<%# Container.DataItem %>'
            Font-Underline="true"
            Target="_blank"
        /></li>
    </ItemTemplate>
    </asp:ListView>
</ItemTemplate>
</asp:TemplateField>
 
Share this answer
 
v3
Comments
Samira Radwan 9-Jun-15 12:13pm    
Thank you, but It looks like it doesn't like the single quotes of .Split('|') within the single quotes of DataSource, any suggestions?
Richard Deeming 9-Jun-15 12:19pm    
Try replacing them with &apos;.
Samira Radwan 9-Jun-15 12:31pm    
Parse Error!, I don't think it's gonna work , looks like c# Split function won't work with html code (')
Richard Deeming 9-Jun-15 12:33pm    
Strange - it works for me in .NET 4.5; are you using an earlier version?

How about this:
DataSource="<%# Eval(&quot;FILES&quot;, &quot;{0}&quot;).Split('|') %>"

If it still doesn't work, you could always write a function in your code-behind to split the string and return the results, and then call that from the data-binding markup.
Samira Radwan 9-Jun-15 12:45pm    
this worked although it gives error in asp.net, thanks a lot :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900