Problem displaying image (binding image) to ImageColumn in datagrid.

Posted on 2006-05-04
Medium Priority
Last Modified: 2011-09-20
Hi there..

Based on a value from my SQLQuery i'm trying to display an image instead of the value in my DataGrid.
The special thing is that i cannot display the value itself inside the grid (due to securityreasons), but i need to use this value to loop through and decide which image (on or off image) should be displayed.

If i hard-code the imageURL like this :
ImageUrl="img\offline24.gif"      it works like a dream..

But.. when i do like this :

ImageUrl='img\<%#Bind("Image") %>'       the image doesn't display, and when looking at properties on the image it shows the <%# Bind("Image") %> as pure text..

So what am i doing wrong here ? or.. how can i do this another way ?

See the code :

--------------The TemplateColumn------------------

<asp:TemplateColumn ItemStyle-Width="40px">
        <asp:Image ID="Image2" runat="server" ImageUrl='img\<%#Bind("Image") %>'></asp:Image>

--------------The TemplateColumn------------------

--------------The Code to generate the Item column and choose image------------------

        Dim ds As New DataSet

        Dim c As New DataColumn
        c.ColumnName = "Image"


        Dim r As DataRow

        For Each r In ds.Tables(0).Rows
            If r.Item(2) = "1" Then
                r.Item(4) = "Online24.gif"
                r.Item(4) = "Offline24.gif"
            End If


        Dim dt As DataTable = ds.Tables(0)

        'return a DataView to the DataTable
        Dim dv As DataView = New DataView(dt)
        dv.Sort = SortField
        Ansatt_Update = dv


--------------The Code to generate the Item column and choose image------------------

Question by:Kripos56

Author Comment

ID: 16607447
More info :

It's .NET 1.x Framework.

and when using this scentence :

<asp:Image ID="Image2" runat="server" ImageUrl='<%# String.Concat("img\", Bind("Image")) %>'></asp:Image>

I'm getting "Bind is not declared"    (same goes with Eval)...

LVL 96

Accepted Solution

Bob Learned earned 1400 total points
ID: 16607692
Try this:

DataBinder.Eval(Container.DataItem, "Image")


Featured Post

Technology Partners: 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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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