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

RotatorScrollDirection - convert the string to object

1 Answer 46 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Bader
Top achievements
Rank 1
Bader asked on 05 Aug 2011, 11:31 PM

Hello,

I have a problem in changing the RotatorScrollDirection using c# code

Here is the code, I'm using:

switch (scrollDirection)
                {
                    case "Down": rotator1.ScrollDirection = RotatorScrollDirection.Down; break;
                    case "Left": rotator1.ScrollDirection = RotatorScrollDirection.Left; break;
                    case "Right": rotator1.ScrollDirection = RotatorScrollDirection.Right; break;
                    case "Up": rotator1.ScrollDirection = RotatorScrollDirection.Up; break;
                }

Is there any way to convert the string to object in order to prevent using the "switch" or "if" statements? for example, convert the string "Right" to the object "RotatorScrollDirection.Right"

Please, I need your help,
It is appreciated to send me the modified code.

Regards,
Bader

1 Answer, 1 is accepted

Sort by
0
Niko
Telerik team
answered on 08 Aug 2011, 11:41 AM
Hello Bader,

Please, refer to the MSDN site for more information on the Enum class and its parsing methods - Parse and TryParse. Here is a simple implementation for the RotatorScrollDirection:
private RotatorScrollDirection ParseDirection(string directionName)
{
    RotatorScrollDirection direction = (RotatorScrollDirection)Enum.Parse(typeof(RotatorScrollDirection), directionName, true);
  
    return direction;
}
private RotatorScrollDirection ParseDirection_DotNET4Only(string directionName)
{
    RotatorScrollDirection direction;
    //this method works in .NET 4 only
    Enum.TryParse<RotatorScrollDirection>(directionName, true, out direction);
  
    return direction;
}

Hope you will find this helpful.

Regards,
Niko
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Rotator
Asked by
Bader
Top achievements
Rank 1
Answers by
Niko
Telerik team
Share this question
or