[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Display image in gridview using ImageField

Posted on 2010-11-13
2
Medium Priority
?
2,327 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 2000 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

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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