This documentation is archived and is not being maintained.

ListItemCollection.FindByText Method

Searches the collection for a ListItem with a Text property that contains the specified text.

[Visual Basic]
Public Function FindByText( _
   ByVal text As String _
) As ListItem
[C#]
public ListItem FindByText(
 string text
);
[C++]
public: ListItem* FindByText(
 String* text
);
[JScript]
public function FindByText(
   text : String
) : ListItem;

Parameters

text
The text to search for.

Return Value

A ListItem that contains the text specified by the text parameter.

Remarks

Use the FindByText method to search the collection for a ListItem with a Text property that contains text specified by the text parameter. If an item is not found in the collection using this criteria, a null reference (Nothing in Visual Basic) is returned.

Example

[Visual Basic] 
Dim myListItem As ListItem = SearchType.SelectedItem
Dim crItem As ListItem 
Dim searchText As String  = TextBox1.Text
If(myListItem.Value = "Name") Then
    If(TextBox1.Text <> "" ) Then        
        Dim searchSubfirst As String = searchText.Substring(0,1)
        Dim searchSubsecond As String = searchText.Substring(1)
        searchText = searchSubfirst.ToUpper()+searchSubsecond.ToLower()
        ' Search by country or region name.                       
        crItem = ItemCollection.FindByText(searchText)    
    End If            
Else
    'Search by country or region code.
    crItem = ItemCollection.FindByValue(searchText.ToUpper())
End If

Dim str As String  = "Search is successful. Match is Found.<br>"
str = str & "The results for search string '" & searchText & "' are:<br>"
str = str & "the country or region code is: " & crItem.Value & "<br>"
str = str & "the country or region name is: " & crItem.Text
' Add the string to the label.
Label1.Text = str
                  

[C#] 
ListItem myListItem = SearchType.SelectedItem;
ListItem crItem = null;
String searchText = TextBox1.Text;
if(myListItem.Value == "Name")
{
    if(TextBox1.Text != "")
    {
        String searchSubfir = searchText.Substring(0,1);
        String searchSubsec = searchText.Substring(1);
        searchText = searchSubfir.ToUpper()+searchSubsec.ToLower();

        // Search by country or region name.
        crItem = ItemCollection.FindByText(searchText);
    }
}
else
{
    // Search by country or region code.
    crItem = ItemCollection.FindByValue(searchText.ToUpper());
}

String str = "Search is successful. Match is Found.<br>";
str =str + "The results for search string '" + searchText + "' are:<br>";
str = str + "the country or region code is " + crItem.Value + "<br>";
str = str + "the country or region name is " + crItem.Text;

// Add the string to the label.
Label1.Text = str;

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

ListItemCollection Class | ListItemCollection Members | System.Web.UI.WebControls Namespace | FindByValue | ListItem | Text

Show: