jQWidgets Forums

jQuery UI Widgets Forums Grid Retrieve image from SQL display in grid

Tagged: , ,

This topic contains 3 replies, has 2 voices, and was last updated by  Gopre400 11 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Retrieve image from SQL display in grid #49487

    Gopre400
    Participant

    Hi I would like to retrieve an image from a field in a SQL table and display it in a grid. Is this possible? Do you have an example or resource?

    Retrieve image from SQL display in grid #49492

    Peter Stoev
    Keymaster

    Hi Gopre400,

    I suppose that by using the cellsrenderer callback function, you will be able to display such image. If your image is stored as byte array, then you can return IMG tag in the cellsrenderer that uses it. Ex: http://stackoverflow.com/questions/9463981/displaying-byte-array-as-image-using-javascript

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    Retrieve image from SQL display in grid #49703

    Gopre400
    Participant

    Thank you Peter, here is what I came up with for those that are curious. It works great.

    Image renderer:
    var imagerenderer = function (row, datafield, value, defaulthtml, columnproperties, rowdata) {
    return ;
    }

    column in grid:
    { text: ‘Image’, datafield: ‘RequestedImage’, width: 100, cellsrenderer: imagerenderer },

    GetImageHandler.ashx
    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim signid As String = context.Request.QueryString(“signid”).ToString
    Using con As New SqlConnection(GetConnectionString(“myconnection”))
    Using cmd As New SqlCommand()
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = “spSRQSignWithImageBySignID”
    cmd.Parameters.AddWithValue(“@pSignID”, signid)
    cmd.Connection = con
    con.Open()
    Dim sdr As SqlDataReader = cmd.ExecuteReader()
    If sdr.HasRows Then
    While sdr.Read()
    Dim imageBytes As Byte() = DirectCast(sdr(2), Byte())
    context.Response.ContentType = “image/jpeg”
    context.Response.BinaryWrite(imageBytes)
    End While
    Else
    context.Response.StatusCode = 404
    End If
    con.Close()
    End Using
    End Using
    End Sub

    Retrieve image from SQL display in grid #49708

    Gopre400
    Participant
    var imagerenderer = function (row, datafield, value, defaulthtml, columnproperties, rowdata) {
          return '<img style="height="100" width="100" src="GetImageHandler.ashx"/>';
     }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.