ListItemCollection.FindByValue(String) Método

Definición

Busca en la colección un ListItem cuya propiedad Value contenga el valor especificado.

public:
 System::Web::UI::WebControls::ListItem ^ FindByValue(System::String ^ value);
public System.Web.UI.WebControls.ListItem FindByValue (string value);
member this.FindByValue : string -> System.Web.UI.WebControls.ListItem
Public Function FindByValue (value As String) As ListItem

Parámetros

value
String

Valor que se va a buscar.

Devoluciones

ListItem que contiene el valor especificado en el parámetro value.

Ejemplos

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;

  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

Comentarios

Utilice el FindByValue método para buscar en la colección un ListItem objeto con una propiedad que contenga el Value valor especificado por el value parámetro . Este método realiza una comparación sin distinción entre mayúsculas y minúsculas y sin distinción entre referencias culturales. Este método no realiza búsquedas parciales ni búsquedas con caracteres comodín. Si no se encuentra un elemento en la colección mediante este criterio, null se devuelve .

Se aplica a

Consulte también