Search code examples
c#.netevalphotovarbinary

How to pass SqlDbType.Varbinary field (using Eval) to C# method in .NET?


In my aspx code I have this (DevExpress Image Control):

<dx:ASPxBinaryImage Value='<%# GetPhoto(Eval("Photo")) %>' ID="BinaryImagePreview"  runat="server" ClientIDMode="AutoID" Width="100px" />

Then in my code behind I have this:

    protected static byte[] GetPhoto(byte[] photo)
    {
        return photo;
    }

My table column Photo is of type Varbinary(Max) I was reading that SqlDbType.Varbinary is mapped to byte[] so there shouldn't be any problems here, but compiler always throws an error:

The best overloaded method match for 'StoreProfile.Admin.GetPhoto(byte[])' has some invalid arguments

Why?

The reason I want to do is is to check if Photo exists (is it null), then I would show some default photo from disk, something like no_photo.jpg.


Solution

  • Uh, Ok. I was missing casting. Calling my method this way solved my problem:

    GetPhoto((byte[])Eval("Photo"))