.NET Framework Class Library
ListItemCollection..::.FindByText Method

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

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Syntax

Visual Basic (Declaration)
Public Function FindByText ( _
    text As String _
) As ListItem
Visual Basic (Usage)
Dim instance As ListItemCollection
Dim text As String
Dim returnValue As ListItem

returnValue = instance.FindByText(text)
C#
public ListItem FindByText(
    string text
)
Visual C++
public:
ListItem^ FindByText(
    String^ text
)
JScript
public function FindByText(
    text : String
) : ListItem

Parameters

text
Type: System..::.String
The text to search for.

Return Value

Type: System.Web.UI.WebControls..::.ListItem
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 matches text specified by the text parameter. This method performs a case-sensitive and culture-insensitive comparison. This method does not do partial searches or wildcard searches. If an item is not found in the collection using this criteria, nullNothingnullptra null reference (Nothing in Visual Basic) is returned.

Examples

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;

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Tags :


Page view tracker