Solved

Error displaying image in gridview with path from access

Posted on 2006-06-19
2
396 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

734 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