This is a migrated thread and some comments may be shown as answers.

[Solved] Conditional Image based on data value

1 Answer 150 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jeffrey bk
Top achievements
Rank 1
jeffrey bk asked on 13 Jan 2010, 07:26 PM
The requirement for a column is to have  3 different images based on  a value  from the database for each row.
e.g  the data behind would be a ageing value      if the value is in the rang 0-30 then it should image A in that row..  if the  value is in the range  30-60 then imageB needs to shown and if the range is over 60 then a imageC needs to be shown.

How do we achieve this ?

regards
jeff

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Jan 2010, 07:03 AM
Hello jeff,

You can use Image inside CellTemplate with IValueConverter for Binding to achieve this. For example:

...
    <Grid.Resources>
        <local:MyConverter x:Key="myconverter" />
    </Grid.Resources>
...
<Image   Source="{Binding YourProperty, Converter="{StaticResource myconverter}" />
...
    public class MyConverter : IValueConverter
    {
        #region IValueConverter

        public object Convert(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
           if(value)
           {
              return YourImage1;
           }
           else
           {
               return YourImage2;
           }
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
jeffrey bk
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or