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

Getting "Datasoruce not set "

1 Answer 46 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
M Kumar
Top achievements
Rank 1
Iron
Veteran
M Kumar asked on 13 Jan 2020, 05:18 AM

Hi , 
  I am try to bind value from server side, for that , i page load i get values in datatable and bind in searchbox, and in DataSourceSelect i filter the values when key in inside search box, but when i key in i get error "Datasoruce not set ", how to bind datasource from server side instead of code behind ?

This is my code
Code Behind
<telerik:RadSearchBox EnableAutoComplete="true" DataValueField="userid"
            DataTextField="con" ID="radsearachUsers"  runat="server"></telerik:RadSearchBox>
--------------------------------

Page_Load
 Dim sqlDA As New SqlDataAdapter("Select con,userid from users", objConnection)
            Dim objDT As New DataTable
            sqlDA.Fill(objDT)

            radsearachUsers.DataSource = objDT
            radsearachUsers.DataValueField = "userid"
            radsearachUsers.DataTextField = "con"
            radsearachUsers.DataBind()

__________________________________

 Protected Sub radsearachUsers_DataSourceSelect(sender As Object, e As SearchBoxDataSourceSelectEventArgs) Handles radsearachUsers.DataSourceSelect
        Dim objConnection As New SqlConnection
        objConnection = New SqlConnection(getconnectionstring())
        objConnection.Open()

        Dim sqlDA As New SqlDataAdapter(" Select * from users where con like '%" & e.FilterString & "%' ", objConnection)
        Dim objDT As New DataTable
        sqlDA.Fill(objDT)
     

        radsearachUsers.DataSource = objDT
        radsearachUsers.DataSourceID = getconnectionstring()
        radsearachUsers.DataTextField = objDT.Rows(0)("Con")
        radsearachUsers.DataValueField = objDT.Rows(0)("userid")
        radsearachUsers.DataBind()
    End Sub

Pls reply asap

Thanks

1 Answer, 1 is accepted

Sort by
0
M Kumar
Top achievements
Rank 1
Iron
Veteran
answered on 13 Jan 2020, 09:49 AM
its ok , i used web service to achieve this, now it working.

Thanks
Tags
SearchBox
Asked by
M Kumar
Top achievements
Rank 1
Iron
Veteran
Answers by
M Kumar
Top achievements
Rank 1
Iron
Veteran
Share this question
or