ListItemCollection.FindByValue(String) メソッド

定義

指定した値を格納している ListItem プロパティを持つ Value をコレクション内で検索します。

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

パラメーター

value
String

検索する値。

戻り値

ListItem

value パラメーターで指定した値を格納している ListItem

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

注釈

このメソッドをFindByValue使用して、パラメーターで指定された値を含むプロパティをValue持つコレクションListItemvalue検索します。 このメソッドは、大文字と小文字を区別し、カルチャを区別しない比較を実行します。 このメソッドでは、部分的な検索やワイルドカード検索は行われません。 この条件を使用してコレクション内に項目が見つからない場合は、 null 返されます。

適用対象

こちらもご覧ください