Solved

Error displaying image in gridview with path from access

Posted on 2006-06-19
2
400 Views
Last Modified: 2012-05-05
Hello, I have an access database IdNumber, name, position and url. I have images in /staffImages. The image name corresponds with the idNumber. So the first row 1 has an image with the name of 1.jpg.
 When I try to open the page and bind the gridview I get the following error. Any Ideas? My code is below:

Error:
Compiler Error Message: BC30109: 'String' is a class type and cannot be used as an expression.

Source Error:

 

Line 20: <ItemTemplate>
Line 21:
Line 22: <asp:Image ID="Image1" ImageUrl='<%# (string) FormatImageUrl( (string) Eval("Url")) %>' runat="server" />
Line 23:
Line 24: </ItemTemplate>
 


My codebehind:
Imports System.Data
Imports System.Data.OleDb

Partial Class staff
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BindData()
    End Sub

    Private Sub BindData()

        Dim myConnection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/ASPNetDB.mdb"))

        Dim ad As OleDbDataAdapter = New OleDbDataAdapter("SELECT idNumber, Name, position,Url FROM Staff", myConnection)

        Dim ds As DataSet = New DataSet()

        ad.Fill(ds)

        GridView1.DataSource = ds

        GridView1.DataBind()

    End Sub
    Protected Function FormatImageUrl(ByVal url As String) As String

        If Not url Is Nothing AndAlso url.Length > 0 Then

            Return ("~/" & url)

        Else
            Return Nothing
        End If

    End Function

End Class


Page code:
          <asp:GridView ID="GridView1" runat="server">
           <Columns>

<asp:BoundField DataField="idNumber" HeaderText="idNumber" />

<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Position" HeaderText="Position" />

<asp:TemplateField HeaderText="Image">

<ItemTemplate>

<asp:Image ID="Image1" ImageUrl='<%# (string) FormatImageUrl( (string) Eval("Url")) %>' runat="server" />

</ItemTemplate>

</asp:TemplateField>

</Columns>
    </asp:GridView>
0
Comment
Question by:gogetsome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
jjardine earned 500 total points
ID: 16938426
It might be that you are trying to cast the result from FormatImageUrl  to a string when if there is no url it returns Nothing  try returning empty string and see what that does.
0
 

Author Comment

by:gogetsome
ID: 16942460
Thanks, that made me look closer. I changed this: <%# (string) FormatImageUrl( (string) Eval("Url")) %> to this and solved the problem: <%# (FormatImageUrl( Eval("Url"))) %>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question