Reputation: 41
I have this code in C#.
<asp:Image runat="server" ID="imgScreenshot" ImageUrl="<%#"data:Image/png;base64," + Convert.ToBase64String((byte[])Eval("Screenshot")) %>"
It converts the varbinary image to a img and displays it. This works perfect in C#, but can't get it working in my VB.net project. Getting the
"Servercode is not properly coded".
Can anyone help me convert it to VB?
Upvotes: 0
Views: 98
Reputation: 2460
In vb.net "&" is the concatenation operator and an array is defined with parentheses "()" instead of brackets "[]". Also, type conversion syntax is a bit different.
I believe this would be the conversion from C# to VB.net:
ImageUrl='<%#"data:Image/png;base64," & Convert.ToBase64String(CType(Eval("Screenshot"), Byte()))%>'
Alternatively as mentioned in the comments you can use the string.format
method:
ImageUrl='<%# String.Format("data:Image/png;base64,{0}", Convert.ToBase64String(CType(Eval("Screenshot"), Byte())))%>'
Upvotes: 1