Solved

Display image in gridview using ImageField

Posted on 2010-11-13
2
2,232 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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