在我的应用程序中,有一个Radcombobox自动完成功能,以及一个查询SQL,该SQL在键入时会加载数据库的寄存器,这项工作有效,但是当我不选择Radcombobox的任何选项时,它的想法是使用查询加载所有寄存器Select * From mytable
,但是不起作用。
这是代码,我尝试放入IF
来验证Radcombobox的值。
我希望从Radcombobox中选择一个选项时,从DB加载所有寄存器
Radcombobox代码:
<telerik:RadComboBox RenderMode="Lightweight"
ID="RadComboBox1"
runat="server"
EmptyMessage="Select Classification"
EnableLoadOnDemand="True"
ShowMoreResultsBox="true"
EnableVirtualScrolling="true"
style="width: 238px"
OnItemsRequested="RadComboBox1_ItemsRequested">
</telerik:RadComboBox>
功能加载代码:
Public Function GetData(text As String) As DataTable
Dim dbConn As MySqlConnection
Dim connStr As String = Nothing
Dim sqlQuery As String = Nothing
Dim table As New DataTable
connStr = ConfigurationManager.ConnectionStrings("db").ConnectionString
dbConn = New MySqlConnection(connStr)
dbConn.Open()
If RadComboBox1.SelectedValue = "Select Classification" Then
Dim consulta As New MySqlDataAdapter("SELECT * from t_clasificacion", ConfigurationManager.ConnectionStrings("db").ConnectionString)
consulta.Fill(table)
Else
Dim consulta As New MySqlDataAdapter("SELECT * from t_clasificacion where nombre_clasif LIKE '%' @text '%'", ConfigurationManager.ConnectionStrings("db").ConnectionString)
consulta.SelectCommand.Parameters.AddWithValue("@text", text)
consulta.Fill(table)
End If
Return table
End Function
Private Shared Function GetStatusMessage(offset As Integer, total As Integer) As String
If total <= 0 Then
Return "No matches"
End If
Return [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total)
End Function
Private Const ItemsPerRequest As Integer = 10
Protected Sub RadComboBox1_ItemsRequested(sender As Object, e As RadComboBoxItemsRequestedEventArgs)
Dim data As DataTable = GetData(e.Text)
Dim itemOffset As Integer = e.NumberOfItems
Dim endOffset As Integer = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count)
e.EndOfItems = endOffset = data.Rows.Count
For i As Integer = itemOffset To endOffset - 1
RadComboBox1.Items.Add(New RadComboBoxItem(data.Rows(i)("nombre_clasif").ToString(), data.Rows(i)("IdClasif").ToString()))
Next
e.Message = GetStatusMessage(endOffset, data.Rows.Count)
End Sub
我的radcmbx的图片