2015-12-02 63 views
1

我正在使用Visual Studio 2015社區版在VB中編寫代碼。如何在webform中使用自動完成的TextBox或組合框

我想創建一個自動完成文本框或組合框在我的Web應用程序從SqlDataSource獲取它的源代碼。但是,看起來像我想要的是不可能的(或至少不是內置的)在web表單中。另外,ComboBoxes似乎根本不可用。對於文本框我已經試過MSDN上提供的方法:

Dim MyTextBox As New TextBox() 
With MyTextBox 
    .AutoCompleteCustomSource = MySource 
    .AutoCompleteMode = AutoCompleteMode.SuggestAppend 
    .AutoCompleteSource = AutoCompleteSource.CustomSource 
    .Location = New Point(20, 20) 
    .Width = Me.ClientRectangle.Width - 40 
    .Visible = True 
End With 

完整的示例在這裏:https://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.autocompletemode(v=vs.110).aspx

我也曾嘗試導入System.Windows.Forms的,但只是給這個警告。

Namespace or type specified in the Imports '<qualifiedelementname>' 
doesn't contain any public member or cannot be found 

但是,我的文本框中唯一可用的屬性是AutoCompleteType,它似乎只能用作Web上用戶輸入的緩存。

如何在我的web應用程序中使用AutoCompleteCustomSource和TextBox的其他自動完成屬性?

回答

0

ASP.Net中ComboBox的等效控件是DropDownList。您可以使用JQuery實現自動完成樣式功能。看到這個鏈接:http://jqueryui.com/autocomplete/#combobox

+0

我還不熟悉JQuery,我正在尋找一個像Windows窗體自動完成一樣簡單的解決方案。但是,如果我找不到這樣的解決方案,我會嘗試一下。 –

+0

我將此標記爲答案,因爲我最終使用了jquery。 –