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

how to formatt each cell of radgrid in code behind?

1 Answer 93 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
anirudha
Top achievements
Rank 1
anirudha asked on 25 Sep 2009, 09:33 AM
Hi All,

i m back to trouble you again.

This time i have one issue that i need to attach differant background images to each cell of radgrid based on certain conditions in code behind.
 i am using template column in radgrid as below.


 

 

<controls:GridViewDataColumn HeaderText="Test" Background="White" ShowDistinctFilters="False" >

 

 

 

<controls:GridViewDataColumn.CellStyle>

 

 

 

<Style TargetType="gridView:GridViewCell">

 

 

 

<Setter Property="Template">

 

 

 

<Setter.Value>

 

 

 

<ControlTemplate TargetType="gridView:GridViewCell">

 

 

 

<StackPanel Width="120" Height="120" Margin="5,5,5,5">

 

 

 

<StackPanel.Background>

 

 

 

<ImageBrush ImageSource="/Images/Header.jpg" />

 

 

 

</StackPanel.Background>

 

 

 

<TextBlock Width="Auto" HorizontalAlignment="Center" Margin="10,30" Text="{Binding SECURITY}" FontFamily="Verdana" Foreground="White" FontSize="10" FontWeight="Bold" TextWrapping="Wrap">

 

 

 

</TextBlock>

 

 

 

<HyperlinkButton Name="{Binding test}" HorizontalAlignment="Left" Margin="40,-30" Background="White" Height="15" Foreground="Green" FontWeight="Bold" Content="P" TargetName="_blank" Click="btnProductTest_Click"></HyperlinkButton>

 

 

 

<HyperlinkButton Name="{Binding test}" HorizontalAlignment="Right" Background="White" Height="15" Margin="40,-50" Foreground="Green" FontWeight="Bold" Content="R" TargetName="_blank" Click="btnRelation_Click"></HyperlinkButton>

 

 

 

</StackPanel>

 

 

 

</ControlTemplate>

 

 

 

</Setter.Value>

 

 

 

</Setter>

 

 

 

</Style>

 

 

 

</controls:GridViewDataColumn.CellStyle>

 

 

 

</controls:GridViewDataColumn>

Now i need to access this column in code behind and change it's background image dynamically.
Is there any event like ItemData_Bound where i could access each cell while data binding itself?

Thanks
Andy ------

 

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 26 Sep 2009, 07:49 AM
Hello anirudha,

The standard approach in such situations is to use an IValueConverter to bind the background image to a specific property of the relevant business object. The Convert method of the converter is called at the binding step and there you may write your own logic to return the required image , depending on the value of the property .

Let me know if you have troubles implementing this approach.

Best wishes,
Pavel Pavlov
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
Calendar
Asked by
anirudha
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or