How the bind the string value to the RadSilder?

4 posts, 0 answers
  1. Justin
    Justin avatar
    5 posts
    Member since:
    Sep 2010

    Posted 18 Jan 2011 Link to this post

    Is it possible to get the string data from the database and bind to the RadSlider control?

    Thanks
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 Jan 2011 Link to this post

    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>>
  3. DevCraft banner
  4. Justin
    Justin avatar
    5 posts
    Member since:
    Sep 2010

    Posted 19 Jan 2011 Link to this post

    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
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Jan 2011 Link to this post

    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>>
Back to Top