how to bind the image dynamically for datagrid in.cs
Posted
by prince23
on Stack Overflow
See other posts from Stack Overflow
or by prince23
Published on 2010-05-18T18:43:46Z
Indexed on
2010/05/18
20:30 UTC
Read the original article
Hit count: 237
silverlight-4.0
|Silverlight
hi, this is my xaml code.
<sdk:DataGrid x:Name="dgMarks" CanUserResizeColumns="False" SelectionMode="Single" AutoGenerateColumns="False" VerticalAlignment="Top" IsReadOnly="True" Margin="13,44,0,0" RowDetailsVisibilityChanged="dgMarks_RowDetailsVisibilityChanged" RowDetailsVisibilityMode="Collapsed" Height="391" HorizontalAlignment="Left" Width="965" SelectionChanged="dgMarks_SelectionChanged" VerticalScrollBarVisibility="Visible" >
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="myButton"
Click="ExpandMarks_Click">
<TextBlock Text="{Binding Level}" TextWrapping="NoWrap" ></TextBlock>
<Image x:Name="imgMarks" Stretch="None"/>
</Button>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="Name" Visibility="Collapsed">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<sdk:Label Content="{Binding Name}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="Marks" Width="80">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<sdk:Label Content="{Binding Marks}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
from database i am getting these values
name marks Level
abc 23 0
xyz 67 1
yu 56 0
aa 89 1
here i am binding these values for datagrid. i have an tricky thing to be done .based on the level i should be binding image if level value is 1 then bind the image. if level value is 0 then do not bind the image for that row
i know this is how we need to handle but where should i write this code in which events?
Image imgLevel = (Image)templateTrendScore.FindName("imgMarks");
if (level1==1)
{
imgLevel .Source = new BitmapImage(new Uri("/Images/image1.JPG", UriKind.Relative));
}
any help would be great thanks in advance
© Stack Overflow or respective owner