Solved

Display image in gridview using ImageField

Posted on 2010-11-13
2
2,242 Views
Last Modified: 2012-05-10
try to display image in gridview row column by passing in Status field in the method with integer 1,2,etc

if 1, it will return filepath , so this filepath will use as string for DataImageUrlField.

but getting this error:
Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ImageField does not have a DataBinding event.

aspx Gridview
-------------
 <asp:ImageField HeaderText="Status" HeaderStyle-CssClass="arialfontgvtitle" DataImageUrlField='<%# getImageByID(Status) %>' ControlStyle-Height="48" ControlStyle-Width="48"></asp:ImageField>

codebehind
----------
 protected string getImageByID(int intstatusid)
    {
        statuspic sp = statuspic.getFilePath_ByStatusID(intstatusid);

        if (sp != null)
        {
            return sp.ImagePath;
        }
        else
        {
            return String.Empty;
        }
        
    }

Open in new window

0
Comment
Question by:doramail05
2 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34127022
Instead of DataImageUrlField='<%# getImageByID(Status) %>'


write like this DataImageUrlField='<%# getImageByID(Eval("Status")) %>'
 
or else

you can use TemplateFiled  inside place a ImageButton or Image and do the same
0
 
LVL 16

Accepted Solution

by:
BurnieP earned 500 total points
ID: 34128235
You cannot bind a value using <asp:ImageField control.

If you want to dynamically set your ImageUrl you need to use a <asp:TemplateField.. /> like I posted below.

So basically replace your <asp:ImageField line with what I posted below and you should get your wanted result.

Hope it helps.
<asp:TemplateField HeaderText="Status" HeaderStyle-CssClass="arialfontgvtitle">
    <ItemTemplate>
        <asp:Image ID="imgStatus" runat="server" ImageUrl='<%# getImageByID((int)Eval("Status")) %>' Height="48" Width="48" />
    </ItemTemplate>
</asp:TemplateField>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 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