This is a migrated thread and some comments may be shown as answers.

Auto Complete issue

1 Answer 55 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
El
Top achievements
Rank 1
El asked on 18 Jul 2009, 06:26 AM
    Protected Sub cmbNames_ItemsRequested(ByVal sender As ObjectByVal e As System.EventArgs) Handles cmbNames.ItemsRequested 
        Dim conn As New SqlConnection("connstringhere"
        Dim strSQL As String = "SELECT * FROM Members WHERE fName LIKE '%" & Me.cmbNames.Text & "%'" 
        Dim cmd As New sqlCommand(strSQL, conn) 
 
        conn.Open() 
        Dim table As New Data.DataTable 
        table.Load(cmd.ExecuteReader(data.CommandBehavior.CloseConnection) 
 
        Me.cmbNames.DataSource = table 
        Me.cmbNames.DataTextField = "fName" 
        Me.cmbNames.DataValueField = "ID" 
        Me.cmbNames.DataBind() 
    End Sub 

    <telerik:RadComboBox ID="cmbNames" runat="server" Skin="Telerik" Width="300px"  
        AllowCustomText="True"  
        AutoPostBack="True" 
        EnableLoadOnDemand="true" MarkFirstMatch="true"
    </telerik:RadComboBox> 

I have the following problem; No matter what i enter it loads all the records from the Table Members. The query is correct as i tested it directly against the SQL Server DB and it works just as expected.

I need it to shows up only the items (records) that match the entry e.g. if i enter Jo i expect to see only the names like John, Jonathan etc.

I guess i am missing some important attribute of the RadComboBox

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Jul 2009, 07:58 AM
Hello,

Give a try with 'e.Text' instead of 'Me.cmbNames.Text' in SQL query string and see whether it is working fine as expected.

C#:
 
Protected Sub cmbNames_ItemsRequested1(ByVal o As ObjectByVal e As RadComboBoxItemsRequestedEventArgs) 
    Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ToString()) 
    Dim strSQL As String = "SELECT * FROM Customers WHERE fName LIKE '%" & e.Text & "%'" 
    Dim cmd As New SqlCommand(strSQL, conn) 
     
    conn.Open() 
    Dim table As New System.Data.DataTable() 
    table.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection)) 
     
    Me.cmbNames.DataSource = table 
    Me.cmbNames.DataTextField = "fName" 
     
    Me.cmbNames.DataBind() 
End Sub 

Thanks,
Princy.
Tags
ComboBox
Asked by
El
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or