This is a migrated thread and some comments may be shown as answers.

How the bind the string value to the RadSilder?

3 Answers 101 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 19 Jan 2011, 02:31 AM
Is it possible to get the string data from the database and bind to the RadSlider control?

Thanks

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 19 Jan 2011, 10:27 AM
Hi Justin,

If you get a string from the database, you can use converters from string to double like so:
<telerik:RadSlider
            Value="{Binding Value, Mode=TwoWay, Converter={StaticResource ByteToDoubleConverter}}"
public class ByteToDoubleConverter : IValueConverter
   {
       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           double? result = 0.0;
           if (value is string)
           {
               double nonNullableResult;
               Double.TryParse(value as string, out nonNullableResult);
               return nonNullableResult;
           }
           else
               if (value is double?)
           {
               result = value as double?;
           }
           else if (value is int?)
           {
               result = (double)(value as int?);
           }
           else if (value is byte?)
           {
               result = (double)(value as byte?);
           }
           return result;
       }
       public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           throw new NotImplementedException();
       }
   }
Feel free to ask if you need further help.

All the best,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Justin
Top achievements
Rank 1
answered on 20 Jan 2011, 05:59 AM
Hi,

Thanks for your replying.

What I am trying to do is  to dispay some string value on the Slider based on the data in the database.

I can use converter to implement the convertion between string and double.

But the problem is the string value is based on the value in database.

Hope that makes sense.

Thanks
0
Petar Mladenov
Telerik team
answered on 20 Jan 2011, 01:51 PM
Hello Justin,

In this case inspect what is the value from the database and update the Convert method accordingly.

Best wishes,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Slider
Asked by
Justin
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Justin
Top achievements
Rank 1
Share this question
or