Click here to Skip to main content
15,889,527 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: How can Create this table in sql Pin
Kornfeld Eliyahu Peter8-Feb-14 21:55
professionalKornfeld Eliyahu Peter8-Feb-14 21:55 
GeneralRe: How can Create this table in sql Pin
thatraja9-Feb-14 20:28
professionalthatraja9-Feb-14 20:28 
Questioninserting data in mysql database using c# Pin
Priyanka Sundaraj8-Feb-14 1:08
Priyanka Sundaraj8-Feb-14 1:08 
AnswerRe: inserting data in mysql database using c# Pin
Wombaticus9-Feb-14 3:10
Wombaticus9-Feb-14 3:10 
QuestionHow to tie a gridview row edit properly Pin
Member 105796217-Feb-14 6:55
Member 105796217-Feb-14 6:55 
AnswerRe: How to tie a gridview row edit properly Pin
Ali Al Omairi(Abu AlHassan)9-Feb-14 11:43
professionalAli Al Omairi(Abu AlHassan)9-Feb-14 11:43 
Questionhow to bind image from database to image control in asp.net Pin
Member 104959267-Feb-14 1:03
Member 104959267-Feb-14 1:03 
AnswerRe: how to bind image from database to image control in asp.net Pin
Richard Deeming7-Feb-14 1:58
mveRichard Deeming7-Feb-14 1:58 
You have two options.

If all of your users are using a recent browser, you can use a Data URI[^] to embed the image. It won't work in IE7 or earlier, and IE8 support is limited.
C#
public static string GuessImageMimeType(byte[] data)
{
    string result = null;
    if (data != null && data.Length > 3)
    {
        if (data[0] == 71 && data[1] == 73 && data[2] == 70)
        {
            result = MediaTypeNames.Image.Gif;
        }
        else if (data[0] == 137 && data[1] == 80 && data[2] == 79)
        {
            result = "image/png";
        }
        else if (data[0] == 66 && data[1] == 77)
        {
            result = "image/bmp";
        }
        else
        {
            for (int index = 0; index < data.Length - 2; index++)
            {
                if (data[index] == 255 && data[index + 1] == 216 && data[index + 2] == 255)
                {
                    result = MediaTypeNames.Image.Jpeg;
                    break;
                }
            }
        }
    }

    return result;
}

public static string BuildImageUrl(byte[] data)
{
    if (data == null || data.Length == 0) return null;

    var sb = new StringBuilder("data:");
    string mimeType = GuessImageMimeType(data);
    if (!string.IsNullOrWhiteSpace(mimeType)) sb.Append(mimeType);

    sb.Append(";base64,");
    sb.Append(Convert.ToBase64String(data));
    return sb.ToString();
}

aspx
<asp:Image runat="server"
    ImageUrl='<%# BuildImageUrl((byte[])Eval("visPic")) %>'
/>



If you need support for older browsers, you'll need to create a generic handler to load and return the image based on the ID, and set the ImageUrl to point to that handler:
aspx
<asp:Image runat="server"
    ImageUrl='<%# Eval("ID", "DisplayVisitorPicture.ashx?ID={0:D}") %>'
/>

There's an example of this approach here: Image Handling In ASP.NET[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


Questionhow to convert image into text Pin
luckyhids7-Feb-14 0:21
luckyhids7-Feb-14 0:21 
AnswerRe: how to convert image into text Pin
Philip Cotan7-Feb-14 11:25
Philip Cotan7-Feb-14 11:25 
GeneralRe: how to convert image into text Pin
luckyhids17-Oct-18 2:50
luckyhids17-Oct-18 2:50 
QuestionAsp.net Pin
Member 105786837-Feb-14 0:15
Member 105786837-Feb-14 0:15 
AnswerRe: Asp.net Pin
Ahmed Bensaid12-Feb-14 22:41
professionalAhmed Bensaid12-Feb-14 22:41 
QuestionBuilt in authentication Pin
larsp7776-Feb-14 1:41
larsp7776-Feb-14 1:41 
AnswerRe: Built in authentication Pin
Richard Deeming6-Feb-14 1:57
mveRichard Deeming6-Feb-14 1:57 
GeneralRe: Built in authentication Pin
larsp7776-Feb-14 2:00
larsp7776-Feb-14 2:00 
GeneralRe: Built in authentication Pin
Ali Al Omairi(Abu AlHassan)6-Feb-14 2:32
professionalAli Al Omairi(Abu AlHassan)6-Feb-14 2:32 
GeneralRe: Built in authentication Pin
Richard Deeming6-Feb-14 2:38
mveRichard Deeming6-Feb-14 2:38 
GeneralRe: Built in authentication Pin
joginder-banger6-Feb-14 4:27
professionaljoginder-banger6-Feb-14 4:27 
QuestionASP.NET MVC Web API - filter query with pagesize Pin
miss7865-Feb-14 22:39
miss7865-Feb-14 22:39 
AnswerRe: filter query with pagesize Pin
Ali Al Omairi(Abu AlHassan)6-Feb-14 1:55
professionalAli Al Omairi(Abu AlHassan)6-Feb-14 1:55 
GeneralRe: filter query with pagesize Pin
miss7866-Feb-14 23:27
miss7866-Feb-14 23:27 
GeneralRe: filter query with pagesize Pin
Ali Al Omairi(Abu AlHassan)7-Feb-14 11:25
professionalAli Al Omairi(Abu AlHassan)7-Feb-14 11:25 
GeneralRe: filter query with pagesize Pin
miss78610-Feb-14 0:37
miss78610-Feb-14 0:37 
QuestionTelerik grid vs. Kendo grid and Ajax calls Pin
littleGreenDude5-Feb-14 8:36
littleGreenDude5-Feb-14 8:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.