共用方式為


ListItemCollection.FindByText(String) 方法

定義

在集合中搜尋 ListItem,其 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

要搜尋的文字。

傳回

ListItem,包含 text 參數所指定的文字。

範例

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 指定的文字。 這個方法會執行區分大小寫且不區分文化特性的比較。 此方法不會執行部分搜尋或萬用字元搜尋。 如果使用這個準則在集合中找不到專案, null 則會傳回 。

適用於

另請參閱