ListItemCollection.FindByText(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
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
要搜索的文本。
返回
包含 text
参数指定的文本的 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
注解
FindByText使用此方法搜索集合中的属性ListItemText,该属性等于参数指定的text
文本。 此方法执行区分大小写且不区分区域性的比较。 此方法不执行部分搜索或通配符搜索。 如果使用此条件在集合中找不到项, null
则返回。