ListItemCollection.FindByText(String) メソッド

定義

指定したテキストと同じ内容の ListItem プロパティを持つ Text をコレクション内で検索します。Searches the collection for a ListItem with a Text property that equals the specified text.

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

パラメーター

text
String

検索するテキストです。The text to search for.

戻り値

ListItem

text パラメーターで指定されたテキストを格納している ListItemA ListItem that contains the text specified by the text parameter.

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

注釈

メソッドを使用し FindByText ListItem て、 Text パラメーターによって指定されたテキストと等しいプロパティを持つのコレクションを検索し text ます。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. この条件を使用してコレクション内に項目が見つからない場合 null は、が返されます。If an item is not found in the collection using this criteria, null is returned.

適用対象

こちらもご覧ください