---
title: "ListBox items TextBlock changes based on condition"  
description: "ListBox items TextBlock changes based on condition"  
author: "Anonymous User"  
published: 2013-09-04  
updated: 2013-09-04  
canonical: https://www.mindstick.com/forum/1443/listbox-items-textblock-changes-based-on-condition  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# ListBox items TextBlock changes based on condition

I [am getting](https://www.mindstick.com/forum/34179/i-am-getting-error-while-assigning-the-data-to-the-array-list) data in [JSON](https://www.mindstick.com/forum/34446/convert-json-string-to-object) and storing in List by

List<[Product](https://www.mindstick.com/articles/75385/full-product-keys)> rootObject = [JsonConvert.DeserializeObject](https://www.mindstick.com/forum/161290/how-does-jsonconvert-deserializeobject-work-in-c-sharp)<List<Product>>(e.Result);

and after that, I am [displaying data](https://www.mindstick.com/forum/309/displaying-data-in-crystal-report-when-data-is-in-xml-file) in [ListBox](https://www.mindstick.com/articles/626/listbox-events-in-c-dot-net) by

productlist.ItemsSource = rootObject;

My xaml [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp):-

```
<ListBox Height="600" HorizontalAlignment="Left" Margin="5,91,0,0" Name="productlist" VerticalAlignment="Top" Width="441"             SelectionChanged="productlistselectionchanged">        <ListBox.ItemTemplate>            <DataTemplate>                <StackPanel Orientation="Horizontal" Height="132">                    <!--    <Image Source="{Binding Path=http://callme4.com/images/classifieds/ad_images/IMG_20130728_132750.jpg}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/> -->                    <StackPanel Width="370">                        <TextBlock Text="{Binding title}" Foreground="#FFC8AB14" FontSize="28" />                        <TextBlock Text="{Binding city}" TextWrapping="Wrap" FontSize="24" /><TextBlock Text="{Binding realdata}" TextWrapping="Wrap" FontSize="24" /> <TextBlock Text="{Binding gender}" TextWrapping="Wrap" FontSize="24" /> <TextBlock Text="{Binding age}" TextWrapping="Wrap" FontSize="24" />                        <TextBlock Text="{Binding price}" TextWrapping="Wrap" FontSize="24" />                    </StackPanel>                </StackPanel>            </DataTemplate>        </ListBox.ItemTemplate>    </ListBox>This is working fine.But i have a condition in textblock.if ( realdata == 1)gender and age should be display and price should be hide.elseprice should be display. and Gender with age should be hide.
```

Please help me.

## Replies

### Reply by Sumit Kesarwani

try this one ..

```
foreach (Product currentProduct in rootObject ) // Loop
through List with foreach{       
if(Product.realdata == 1) Price = "";            else
{Gender =""; Age="";}}productlist.ItemsSource = rootObject;
```


---

Original Source: https://www.mindstick.com/forum/1443/listbox-items-textblock-changes-based-on-condition

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
