ListItemCollection.FindByText Method
.NET Framework 3.0
Searches the collection for a ListItem with a Text property that contains the specified text.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
Use the FindByText method to search the collection for a ListItem with a Text property that contains 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, a null reference (Nothing in Visual Basic) is returned.
ListItem myListItem = SearchType.get_SelectedItem();
ListItem crItem = null;
String searchText = TextBox1.get_Text();
if(myListItem.get_Value().Equals("Name")) {
if(!(TextBox1.get_Text().Equals(""))) {
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.get_Value() + "<br />";
str = str + "the country or region name is "
+ crItem.get_Text();
// Add the string to the label.
Label1.set_Text(str);
Community Additions
ADD
Show: