Невозможно просмотреть изображение из базы данных при нажатии кнопки изображение в GRIDVIEW
In my datagridview I have an asp imagebutton that on client click enables viewing an image in a Sql Server table. When I click the image button a new browser window opens where I will view the image. When I click on an image button the new windows throws the following error: Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC31419: 'IsNot' requires operands that have reference types, but this operand has the value type 'Boolean'. Line 41: Dim buffer As [Byte]() = ds.Tables(0).Rows(0).Item("C_img") Line 42: End If Line 43: If Buffer IsNot Nothing Then Line 44: 'Response.ContentType = "application/pdf" Line 45: Response.ContentType = ds.Tables(0).Rows(0).Item("P_FILETYPE") Code in page for gridview: MARKUP(For 1 of the image buttons) <asp:TemplateField HeaderText="View Payslip"> <ItemTemplate> <asp:ImageButton ID="LinkButton62" ToolTip="View" AlternateText="View" CommandName="SelectP" runat="server" CommandArgument='<%#Eval("ID")%>' ImageUrl="~/Images/view2.jpg" Height="40px" Width="40px" ImageAlign="Middle" CausesValidation="False" /> </ItemTemplate></asp:TemplateField> <asp:TemplateField HeaderText="Type" Visible ="false" ><EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Visible ="false" Text='<%# Bind("P_IMG") %>'> </asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label32"runat="server" Visible ="false" Text='<%# Bind("P_IMG") %>'></asp:Label> <asp:TextBox ID="txtDocIdP" runat="server" Text='<%#Eval("ID")%>' Visible="False"></asp:TextBox> </ItemTemplate> </asp:TemplateField> CODE-BEHIND Protected Sub grdData_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles grdData.RowCommand If e.CommandName = "SelectP" Then Dim docID = e.CommandArgument Dim strscript As String strscript = "<script language=JavaScript>" strscript += "window.open('viewDocument.aspx?id=" & docID & "');" strscript += "</script>" ClientScript.RegisterStartupScript(Me.GetType(), "newwin", strscript) ElseIf e.CommandName = "SelectC" Then Dim docID = e.CommandArgument Dim strscript As String strscript = "<script language=JavaScript>" strscript += "window.open('viewDocument.aspx?idapp=" & docID & "');" strscript += "</script>" ClientScript.RegisterStartupScript(Me.GetType(), "newwin", strscript) ElseIf e.CommandName = "Select" Then Dim ID = e.CommandArgument cmd = New SqlCommand("update ONLINELOANS set ACCEPTED=1 where ID='" & ID & "'", con) If con.State = ConnectionState.Open Then con.Close() End If con.Open() If cmd.ExecuteNonQuery() Then msgbox("Record Successfully Accepted") End If End If End Sub Code bEhind (view.Document.aspx) Imports System.Data Imports System.Data.SqlClient Imports System.Net Partial Class viewDocument Inherits System.Web.UI.Page Dim cmd As SqlCommand Dim adp As SqlDataAdapter Dim con As New SqlConnection Dim connection As String Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load Page.MaintainScrollPositionOnPostBack = True con = New SqlConnection(ConfigurationManager.ConnectionStrings("Constring").ConnectionString) If Not IsPostBack Then Dim docID = Request.QueryString("id") Dim docIDapp = Request.QueryString("idapp") If Request.QueryString("id") <> "" Then cmd = New SqlCommand("Select * from ONLINELOANS where id = '" & docID & "'", con) 'ElseIf Request.QueryString("entity") <> "" Then ' cmd = New SqlCommand("Select * from PROCURING_DOCUMENTS where id = '" & docID & "'", con) 'Else ' cmd = New SqlCommand("Select * from CAPITAL_DOCUMENTS where id = '" & docID & "'", con) End If If Request.QueryString("idapp") <> "" Then cmd = New SqlCommand("Select * from ONLINELOANS where id = '" & docID & "'", con) 'ElseIf Request.QueryString("entity") <> "" Then ' cmd = New SqlCommand("Select * from PROCURING_DOCUMENTS where id = '" & docID & "'", con) 'Else ' cmd = New SqlCommand("Select * from CAPITAL_DOCUMENTS where id = '" & docID & "'", con) End If Dim ds As New DataSet adp = New SqlDataAdapter(cmd) adp.Fill(ds, "QD") Dim client As New WebClient() 'Dim buffer As [Byte]() = client.DownloadData(ds.Tables(0).Rows(0).Item("DOC_DATA")) If Request.QueryString("id") <> "" Then Dim buffer As [Byte]() = ds.Tables(0).Rows(0).Item("P_img") End If If Request.QueryString("idapp") <> "" Then Dim buffer As [Byte]() = ds.Tables(0).Rows(0).Item("C_img") End If If Buffer IsNot Nothing Then 'Response.ContentType = "application/pdf" Response.ContentType = ds.Tables(0).Rows(0).Item("P_FILETYPE") 'msgbox(ds.Tables(0).Rows(0).Item("DOC_TYPE")) 'Response.ContentType = ds.Tables(0).Rows(0).Item("C_FILETYPE") Response.AddHeader("content-length", Buffer.Length.ToString()) Response.BinaryWrite(Buffer) End If End If End Sub Public Sub msgbox(ByVal strMessage As String) 'finishes server processing, returns to client. Dim strScript As String = "<script language=JavaScript>" strScript += "window.alert(""" & strMessage & """);" strScript += "</script>" Dim lbl As New System.Web.UI.WebControls.Label lbl.Text = strScript Page.Controls.Add(lbl) End Sub End Class In the database I have 3 columns relating to an image i.e P_IMG (datatype image), P_FILETYPE(datatype varchar) and P_FILENAME(datatype varchar).The other image to be downloaded in gridview also has same attributes in database (C_IMG,C_FILETYPE,C-FILENAME). I have the following errors in viewDocument.aspx; 1.Value of type Boolean cannot be converted to Byte() 2.Lenght is not a member of Boolean
Что я уже пробовал:
Я пробовал использовать обработчик изображений для просмотра изображений в gridview, но пока это не практично для моих требований. Мне нужно просмотреть изображение в новом окне браузера, как указано выше в моем коде