afis ni
afis ni

Reputation: 21

How to display multiple images in a new window using popup from database in asp.net?

What I would really like to do is have a ViewImage button on container so that when that is clicked, the images are displayed on a new page . How would I do that? asp:Image ID="Image2" runat="server" Height ="40" Width ="60" Eval(("Cust_ID"),"~/crm/DisplayCategoryPicture.aspx?Cust_ID={0}) ") %>'
onclick="CreatepopUp1(this.src);" />

Private Sub CusImgShow() Try

        'Const SQL As String = "SELECT COALESCE(Civilimg1, civilimg2) AS  civilid  FROM [NewCus] WHERE [Cust_ID] = @Cust_ID"
        Const SQL As String = "SELECT Civilimg1,civilimg2 FROM [NewCus] WHERE [Cust_ID] = @Cust_ID2"
        Dim myCommand As New SqlCommand(SQL, myConnection)
        myCommand.Parameters.AddWithValue("@Cust_ID", Request.QueryString("Cust_ID"))
        'Dim adr As New SqlDataAdapter(myCommand)
        myConnection.Open()
        Dim myReader As SqlDataReader = myCommand.ExecuteReader

        If myReader.Read Then
            Response.ContentType = "image/JPEG"
            Response.BinaryWrite(myReader("Civilimg1"))
            Response.ContentType = "image/JPEG"
            Response.BinaryWrite(myReader("civilimg2"))
        End If

        myReader.Close()

        myConnection.Close()
    Catch ex As Exception
        'MsgBox(ex.Message)
    End Try
End Sub

Upvotes: 0

Views: 784

Answers (1)

SmartDev
SmartDev

Reputation: 2862

You have to make a page that will show one image at a time.

Example: ~/crm/DisplayCategoryPicture.aspx?Cust_ID={Cust_ID}&type={ImageType}.

Then you will update you asp.net code similar to this (you could improve this, VB.net is not my strongest point):

Const SQL As String = "SELECT @ImageType FROM [NewCus] WHERE [Cust_ID] = @Cust_ID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@Cust_ID", Request.QueryString("Cust_ID"))
myCommand.Parameters.AddWithValue("@ImageType", Request.QueryString("ImageType"))

myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader

If myReader.Read Then
    Response.ContentType = "image/JPEG"
    Response.BinaryWrite(myReader(Request.QueryString("ImageType")))
End If

Then in your first aspx page (I'm guessing you already have the code for CreatepopUp1, right?):

<a href="[URL to second page]" onclick="CreatepopUp1(this.src);" />Click here see images</a>

And in the aspx of the second page (the one that opens):

<asp:Image ID="Image1" runat="server" Height ="40" Width ="60" ImageUrl="~/crm/DisplayCategoryPicture.aspx?Cust_ID=15&ImageType=Civilimg1' />
<asp:Image ID="Image2" runat="server" Height ="40" Width ="60" ImageUrl="~/crm/DisplayCategoryPicture.aspx?Cust_ID=15&ImageType=Civilimg2' />

Of course, use your own Cust_ID values or set them from the code behind.

Upvotes: 0

Related Questions