How to display required data of database in Silverlight 4.0 RRS feed

  • Question

  • Hello, I had one database and  sucessuflly displayed that database in the Silverlight application suing WCF RIA service.

    Now the problem is that, I have lots of content in my database, which I don't want to show?  I want to show my displayed datagrid as:

    For example: If any user enter his name, his address but he doesn't enter his phone number from my dataform then, in my display I want to dispaly only those thing that he has put. Is it possible to do. Any idea. Please help me.

    And if another user enter his name, his phone number but not his address then I want to display different information on his name. 

    Hope you guys understand my problem.

    I need help .

    Monday, April 18, 2011 10:35 PM


All replies

  • Basically, you need a datagrid with all the columns and based on the value entered by the user, you must set the datagrid column visibility, Right?

    Hope your datagrid is custom templated. You can use a converter and set the visibility or column width

    Check this

    <data:DataGridTextColumn Visibility="{Binding Path=Address, Converter={StaticResource MyVisibilityConverter}}" Header="Address" Width="*" Binding="{Binding Path=Address}" IsReadOnly="True"/>


    Here is the converter

    public class VisibilityConverter : IValueConverter
            #region IValueConverter Members
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                string bindValue = System.Convert.ToString(value);
                Visibility retVal = string.IsNullOrEmpty(bindValue) ? Visibility.Collapsed : Visibility.Visible;
                return retVal;
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                return string.Empty;


    Monday, April 18, 2011 11:56 PM
  • Thank you. But got one problem:

    the type or namespace name 'IValueConverter' does not exist in the namespace system'.

    Which namespace should I add above. Can you tell me.

    Tuesday, April 19, 2011 11:24 AM
  • System.Windows.Data

    Tuesday, April 19, 2011 11:33 AM
  • Thank you. It resolved it. 

    But in XAML; Converter={StaticResource MyVisibilityConverter} . The resource "MyVisibilityConverter" cannot be resolved.

    How can I solve the problem?

    Tuesday, April 19, 2011 11:57 AM
  • I can debug my application, but when I click my page having database then it returns to the code and says:

    Failed to create a 'System.Windows.Data.IValueConverter' from the text 'StaticResource MyVisibilityConverter'. [Line: 27 Position: 155]

    Whats the problem.

    Tuesday, April 19, 2011 1:05 PM
  • Now I am totally confused with this one. As I am new, I am not getting properly.

    Can you help me:

    For example,

    I have two checkbox and one text box is there.

    For those two checkbox, if I click one then just below it there is database grid, where it will dispaly the only one that I have clicked. Similar for other who put name in text box and choose the checkbox.

    I have tried your code. Just I havenot changed anything but I bind my data of textbox and two checkbox. 

    In .cs, is there anything that I have to change.

    Wednesday, April 20, 2011 12:07 AM
  • Hi,

     First you create domain service for CRUD operation on your dataform as wll as Datagrid.

     When you enter the in formation from dataform you save the your enterd null value to save int the databse

    at the time of display in datagrid you dispaly null on that emplty record



    Wednesday, April 20, 2011 1:31 AM
  • For the visibility/collapsed of my checkbox I have done like this:

    IN XAML#:


            <converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>


            <converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>


    <sdk:DataGridCheckBoxColumn x:Name="abdominalPainColumn" Binding="{Binding AbdominalPain}" Header="Abdominal Pain" Width="SizeToHeader" Visibility="{Binding BoolProperty, Converter={StaticResource BoolToVisibilityConverter}}" />

    And in C#,

    public class BoolToVisibilityConverter : IValueConverter


                #region IValueConverter Members

                public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)


                    if (parameter == null)


                        return ((bool)value == true) ? Visibility.Visible : Visibility.Collapsed;


                    else if (parameter.ToString() == "Inverse")


                        return ((bool)value == true) ? Visibility.Collapsed : Visibility.Visible;


                    return false;


                public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)


                    throw new NotImplementedException();




    With this, in XAML where I bold it, there i got the error saying: The type"converter.BoolToVisibilityConverter" wasnot found.Verify that you are not missing an assembly reference.

    Wednesday, April 20, 2011 2:07 PM
  • In a Visibility Converter Method, you are not supposed to send

    return false;


    And for the error message, you may install Visual Studio SP1... I guess, there wont be any problem runnin the applicaiton

    Wednesday, April 20, 2011 10:50 PM
  • Hi Udhyan,

    What's your issue going now?

    Best regards,


    Thursday, April 28, 2011 4:47 AM
  • Thank you for your interset. I have solved this issue with different way. I haven't use this way, but I use other option that works for me.

    Once again, thank you for your concern.



    Sunday, May 1, 2011 8:16 PM