Export (0) Print
Expand All

ListItemCollection.FindByText Method

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

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

public ListItem FindByText(
	string text
)

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.

Use the FindByText method to search the collection for a ListItem with a Text property that equals 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, null is returned.

            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;

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Show:
© 2015 Microsoft