Question

Please i need help in converting the image url property of an image control written in C# to its equivalent in vb.net. I am following a tutorial which i got from this site on how to display images on a gridview using base64 this is the url of the tutorial. http://dotnetawesome.blogspot.in/2013/10/how-to-insert-image-into-database-and.html. The tutorial was written in C# please i need the equivalent of this in vb.net

<ItemTemplate>
    <asp:Image ID="Image1" runat="server" Width="100px" ImageUrl='<%#Eval("Picture").ToString() == ""?"": GetImageString64((byte[])Eval("Picture")) %>' />
</ItemTemplate>
Was it helpful?

Solution

Use If Operator

<ItemTemplate>
    <asp:Image ID="Image1" runat="server" Width="100px" ImageUrl='<%# If(Eval("Picture").ToString() = "", "", GetImageString64(CType(Eval("Picture"), Byte()))) %>' />
</ItemTemplate>

Here's how it works:

If( argument1, argument2, argument3 )

the above syntax will evaluate argument1. If argument1 is true, it will return argument2, otherwise it will return argument3.

In your case argument1 is Eval("Picture").ToString() = "", argument2 is "", and argument3 is GetImageString64(CType(Eval("Picture"), Byte())).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top