This documentation is archived and is not being maintained.

ListItemCollection.FindByValue Method

Searches the collection for a ListItem with a Value property that contains the specified value.

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

public ListItem FindByValue (
	string value
)
public ListItem FindByValue (
	String value
)
public function FindByValue (
	value : String
) : ListItem

Parameters

value

The value to search for.

Return Value

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

Use the FindByValue method to search the collection for a ListItem with a Value property that contains value specified by the value 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, a null reference (Nothing in Visual Basic) 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;


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: