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

Kiran

1 Answer 53 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 30 Dec 2010, 02:16 PM
Hi,

Here is the scenario where i have to search for an element in the combobox.

an element - value being a string.

I am using HtmlSelect control for combobox.
but htmlSelectControl.Option.Contains( "is accepting an HtmlOption ")

how do i convert a string to a HtmlOption object??

1 Answer, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 05 Jan 2011, 01:52 PM
Hello Kiran,
      you can't convert a String to an HtmlOption object. You need to pass an HtmlOption object to the method htmlSelectControl.Option.Contains(). When you pass the object the method checks whether this object  is found in the Collection of the HtmlSelect element.

You can't use the method since you can't get your hand on an HtmlOption object. You can create one yourself but htmlSelectControl.Option.Contains() will return False for that object because it won't be among the collection of the HtmlSelect.

Instead let me suggest a different approach to achieve what you want:
System.Collections.ObjectModel.ReadOnlyCollection<HtmlOption> options
                      = MyHtmlSelect.Options;
 
            foreach (HtmlOption item in options)
            {
                if (item.Text.Contains("StringImLookingFor"))
                {
                    Log.WriteLine("The option was found!");
                    break;
                }
 
            }

Let me know if this solution works for!

Greetings,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
Kiran
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Share this question
or