how to formatt each cell of radgrid in code behind?

2 posts, 0 answers
  1. anirudha
    anirudha avatar
    17 posts
    Member since:
    Jan 2009

    Posted 25 Sep 2009 Link to this post

    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 ------

     

  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 26 Sep 2009 Link to this post

    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.
  3. DevCraft banner
Back to Top