RSS

Tag Archives: How do you set the backgound image of a grid in c# (code behind)

How to set image source code behind in silverlight


Hi  Dear…

if your want to change image dynamically of RadGridview in Silverlight with specific Condition then your use this code and be happy

ClientSite

<telerik:GridViewColumn Width=”auto”>
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>

<telerik:RadButton  x:Name=”lbtnInActive”   Command=”Edit” CommandParameter=”{Binding Listidpk}” Click=”lbtnInActive_Click”  >
<telerik:RadButton.Content>
<StackPanel Orientation=”Horizontal” Margin=”0″>
<Image Source=”../Images/icon-Active.png” Width=”30″ Height=”31″ x:Name=”activeICon”/>
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

CodeBehind:

private void grdList_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if (e.DataElement != null)
{
if (e.Row.DataContext != null)
{
var button = e.Row.ChildrenOfType<RadButton>().Where(b => b.Name == “lbtnInActive”).FirstOrDefault();
var imgicon = e.Row.ChildrenOfType<Image>().Where(b => b.Name == “activeICon”).FirstOrDefault();
tbllists tblst = e.Row.DataContext as tbllists;

if (Convert.ToString(tblst.Liststatus)== “Active”)
{
button.Tag = “Active”;
ToolTipService.SetToolTip(button, “Change Status To InActive”);
imgicon.Source = new BitmapImage(new Uri(“../Images/icon-Active.png”, UriKind.RelativeOrAbsolute));

}
else if (Convert.ToString(tblst.Liststatus)==”InActive”)
{

button.Tag = “InActive”;
ToolTipService.SetToolTip(button, “Change Status To Active”);
imgicon.Source = new BitmapImage(new Uri(“../Images/icon-inactive.png”, UriKind.RelativeOrAbsolute));

}
else {
button.Tag = “Active”;
imgicon.Source = new BitmapImage(new Uri(“../Images/icon-pending.png”, UriKind.RelativeOrAbsolute));
ToolTipService.SetToolTip(button, “Change Pendding To Active”);
}

}
}
}

 

Advertisements
 
Leave a comment

Posted by on March 30, 2012 in Silverlight

 

Tags: , , , , ,