what is way to use asp:imagefield other than simple replacement

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Hi,

<asp:imagefield dataimageurlfield="LastName"
dataimageurlformatstring="~\Images\{0}.jpg"
alternatetext="Employee Photo"
nulldisplaytext="No image on file."
headertext="Photo"
readonly="true"/>

Is the sample on MSDN doc.

But what about I need diffrent rules other than simple string replacement
{0}, e.g. use different images based on data field which type is an enum?
So a translation needed, how to do that declaratively?

I know I can accomplish same goal using <asp:TemplateField>, but just
thought there should be a way to make <asp:imagefield> more useful.

Thanks!
Ryan
 
Hi,

 <asp:imagefield dataimageurlfield="LastName"
            dataimageurlformatstring="~\Images\{0}.jpg"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"
            readonly="true"/>

Is the sample on MSDN doc.

But what about I need diffrent rules other than simple string replacement
{0}, e.g.  use different images based on data field which type is an enum?
So a translation needed, how to do that declaratively?

I know I can accomplish same goal using <asp:TemplateField>,  but just
thought there should be a way to make <asp:imagefield> more useful.

Thanks!
Ryan

Ryan,

ImageField is used to show images using links from a data source. You
can change data source to return final ulrs, for example, for SQL
Server it could be something like this

SELECT photoid,
CASE
WHEN phototypeid = '1' THEN 'big1.gif'
WHEN phototypeid = '2' THEN 'big2.gif'
WHEN phototypeid = '3' THEN 'big3.gif'
AS photourl
.....

If you need other rules and you cannot change data source, then it
makes no big sense to use ImageField (e.g. use TemplateField
instead).

Hope this helps
 
Back
Top