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

Conditional Formatting of an ImageColumn

2 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johnathan
Top achievements
Rank 1
Johnathan asked on 09 Sep 2010, 11:25 AM
I have a grid which has a number of databound columns (all created in code)
I have carried out a number of conditional formatting operations for example
Private Sub radgrid_databound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
      'Is it a GridDataItem
      If (TypeOf (e.Item) Is GridDataItem) Then
          Dim dataBoundItem As GridDataItem = e.Item
          If Left(dataBoundItem("ChangeFromPrevious").Text, 1) = "-" Then
              dataBoundItem("ChangeFromPrevious").ForeColor = Color.Red
          End If
      End If
  End Sub

I have now added a gridimagecolumn to my table which I want to display an arrow image pointing up or down depending if my databound column "changeFromPrevious" is positive or negative.

I am hoping to simply change the imageURL of the gridImageColumn, but I am unclear how and from which event I should do this.
ie do I do this on the databound condition dataitem, if so how do I access the imagecolumn.imageurl
or
do I do this as each image in the  GridImageColumn is created, if so how do get the databound item "changedfromPrevious" to apply conditions.
or is there a better approach?

Thanks

Johnathan 

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 09 Sep 2010, 12:27 PM
Hi Johnathan,

Column properties are changed in the ColumnCreated event. However, you do not want to change a column property in this case, but the ImageUrl of a particular image on a particular item (row) - so you will use ItemDataBound again.

The image is accessible like this:

dataBoundItem("ImageColumnUniqueName").Controls(0)

http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

You can also use a GridTemplateColumn instead of a GridImageColumn:

http://www.telerik.com/help/aspnet-ajax/grdconditionalimagedisplayingridcolumn.html


All the best,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
jajanes
Top achievements
Rank 1
answered on 06 Feb 2012, 07:33 PM
  
Tags
Grid
Asked by
Johnathan
Top achievements
Rank 1
Answers by
Dimo
Telerik team
jajanes
Top achievements
Rank 1
Share this question
or