Solved

Display image in gridview using ImageField

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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