【发布时间】:2013-03-05 05:51:55
【问题描述】:
试图在图像控件中显示数据库中的图像...第三天...到目前为止没有运气...
Employee.aspx 上的显示按钮
Protected Sub DisplayButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DisplayButton.Click
bind()
GridView1.Visible = "True"
If EmployeeIDTextBox.Text = "" Then
MsgBox("Please enter EmployeeID!")
Else
Image1.ImageUrl = "~/HttpHandler.ashx?EmployeeID=" & EmployeeIDTextBox.Text
End If
End Sub
这是处理程序:
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World!")
Dim EmployeeID As Integer
If (Not (context.Request.QueryString("EmployeeID")) Is Nothing) Then
EmployeeID = Convert.ToInt32(context.Request.QueryString("EmployeeID"))
Else
Throw New ArgumentException("No parameter specified")
End If
Dim imageData() As Byte = {}
' get the image data from the database using the employeeId Querystring
context.Response.ContentType = "image/jpeg"
' You can retrieve this also from the database
context.Response.BinaryWrite(imageData)
End Sub
这是我想在其中显示图像的图像控件(在 Employee.aspx 上)
<asp:Image ID="Image1" runat="server" imageUrl="HttpHandler.ashx?EmployeeID=7" />
得到了很多帮助...似乎还不够...
【问题讨论】:
-
当你把
HttpHandler.ashx?EmployeeID=7的完整url直接放到浏览器中,图片能打开吗?如果没有,您应该先修复该部分。 -
它不会...如果我知道如何解决它...
-
context.Response.ContentType = "image/jpeg"将是必需的。确保类型正确 -
类型正确...
标签: asp.net