如何使用asp.net中的数据库弹出窗口在新窗口中显示多个图像?

时间:2014-11-17 15:05:24

标签: asp.net vb.net sql-server-2008

我真正想要做的是在容器上放置一个ViewImage按钮,以便在单击该按钮时,图像显示在新页面上。我该怎么办? asp:图像ID ="图像2" RUNAT ="服务器"高度=" 40"宽度=" 60" Eval((" Cust_ID"),"〜/ crm / DisplayCategoryPicture.aspx?Cust_ID = {0})")%>'
 的onclick =" CreatepopUp1(this.src);" />

Private Sub CusImgShow()         尝试

        '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

1 个答案:

答案 0 :(得分:0)

您必须创建一个一次显示一个图像的页面。

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

然后你会更新你的 asp.net 代码(你可以改进这个,VB.net不是我的最强点):

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

然后在您的第一个 aspx 页面中(我猜测您已经拥有CreatepopUp1的代码,对吧?):

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

在第二页(打开的那个)的 aspx 中:

<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' />

当然,请使用您自己的Cust_ID值或从后面的代码中设置它们。