problem with ajax toolkit slideshow extender

yuan22m

Member
Joined
Jul 22, 2009
Messages
8
Programming Experience
Beginner
I am using the slideshowextender control to display images from database. I am using image handler to retrieve images from database. My problem is when i am using for loop to populate the slide for the slideshowextender images wont display but if i do a manual add to array it works. Below is the code for GetSlides

VB.NET:
<System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethod()> _
    Public Shared Function GetSlides(ByVal contextKey As String) As AjaxControlToolkit.Slide()
      

        'Return (imgSlide)
        Dim propID As Long = CLng(contextKey)
        Dim mTotolrows As Integer = 0
        Dim mName As String = ""
        Dim mDescription As String = ""
        Dim propImageID As Long
        Dim mDT As DataTable
        mDT = mproperty.SelectPhotoRecByForeignKeyID(propID)
        If mDT.Rows.Count Then
            mTotolrows = mDT.Rows.Count - 1
            Dim imgSlide As AjaxControlToolkit.Slide() = New AjaxControlToolkit.Slide(mTotolrows) {}


            For mCount As Integer = 0 To mDT.Rows.Count - 1

                mName = IIf(IsDBNull(mDT.Rows(mCount).Item("PhotoName")), "", mDT.Rows(mCount).Item("PhotoName"))
                mDescription = IIf(IsDBNull(mDT.Rows(mCount).Item("Description")), "", mDT.Rows(mCount).Item("Description"))
                propImageID = mDT.Rows(mCount).Item("PropertyPhotoID")
                imgSlide(mCount) = New AjaxControlToolkit.Slide("~/ShowImage.ashx?id=" & propImageID, "test", "test")

            Next
            'below work when removing with out the for loop
            'imgSlide(0) = New AjaxControlToolkit.Slide("ShowImage.ashx?id=2", "test", "test")
            'imgSlide(1) = New AjaxControlToolkit.Slide("ShowImage.ashx?id=3", "tset", "test")
            'imgSlide(2) = New AjaxControlToolkit.Slide("ShowImage.ashx?id=4", "tset", "test")

            Return imgSlide
        Else
            Return Nothing
        End If
    End Function

Did i miss something in my code?
Thank you.
 
Here is my code for the ShowImage.ashx

VB.NET:
Imports System.Web
Imports System.Web.Services
Imports System
Imports System.Configuration
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient

Public Class ShowImage
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim mRefID As Int32
        If Not context.Request.QueryString("id") Is Nothing Then
            mRefID = Convert.ToInt32(context.Request.QueryString("id"))
        Else
            Throw New ArgumentException("No parameter specified")
        End If

        context.Response.ContentType = "image/jpeg"
        Dim strm As Stream = ShowPropertyPhoto(mRefID)
        Dim buffer As Byte() = New Byte(4095) {}
        Dim byteSeq As Integer = strm.Read(buffer, 0, 4096)

        Do While byteSeq > 0
            context.Response.OutputStream.Write(buffer, 0, byteSeq)
            byteSeq = strm.Read(buffer, 0, 4096)
        Loop
        context.Response.BinaryWrite(buffer)

    End Sub

    Public Function ShowPropertyPhoto(ByVal mRefID As Long)

        Dim conn As String = ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString
        Dim connection As SqlConnection = New SqlConnection(conn)
        Dim sql As String = "SELECT Photo FROM tblPropertyPhoto WHERE PropertyPhotoID = @ID"
        Dim cmd As SqlCommand = New SqlCommand(sql, connection)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@ID", mRefID)
        connection.Open()
        Dim img As Object = cmd.ExecuteScalar()
        Try
            Return New MemoryStream(CType(img, Byte()))
        Catch
            Return Nothing
        Finally
            connection.Close()
        End Try
    End Function

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class
 
Back
Top