Solved

Display image in gridview using ImageField

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now