RadSearch Errors out

2 posts, 1 answers
  1. Kevin
    Kevin avatar
    265 posts
    Member since:
    Jun 2011

    Posted 16 Jan 2014 Link to this post

    I pretty much duplicated the web service and example from the telerik example site but my web serive always returns the following error and I am wondering If I am missing some code somewhere.

    Object reference not set to an instance of an object.

    The other question I have is once it returns correctly how do I get at the value.

                                <td>Personnel Name: </td>
                                <td><telerik:RadSearchBox ID="rdSearch" runat="server" EmptyMessage="Type Last Name First Name" WebServiceSettings-Path="~/AutoComplete.asmx" WebServiceSettings-Method="GetNames"
                                    EnableAutoComplete="true" MinFilterLength="2" MaxResultCount="20" ShowSearchButton="false" OnSearch="RadSearchBox3_Search"></telerik:RadSearchBox></td>
    public SearchBoxItemData[] GetNames(SearchBoxContext context)
            DataTable data = GetData(context.Text);
            List<SearchBoxItemData> result = new List<SearchBoxItemData>();
            for (int i = 0; i < data.Rows.Count; i++)
                SearchBoxItemData itemData = new SearchBoxItemData();
                itemData.Text = data.Rows[i]["strFullname"].ToString();
                itemData.Value = data.Rows[i]["intPersonnelId"].ToString();
            return result.ToArray();
        private static DataTable GetData(string filterString)
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ProdConnection"].ConnectionString);
            SqlCommand command = new SqlCommand("SELECT intPersonnelId, strFullname FROM MnNgPersonnel.dbo.tblMNNatPersonnel WHERE strFullname LIKE ' + @filterString + '%' ORDER BY strFullname");
            command.Parameters.AddWithValue("@filterString", filterString);
            command.Connection = connection;
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataTable data = new DataTable();
            return data;

  2. Answer
    Dimitar avatar
    356 posts

    Posted 17 Jan 2014 Link to this post

    Hello Kevin,

    The error you encounter is a general one and could occur as a result of different reasons.
    However, I have replicated such an error when the connection string declaration is missing in the web.config file.

    I have prepared a runnable sample project for you to help you setup your project. It is attached to this message.
    For this sample, the connection string declaration in the web.config is as follows:
    <add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Northwind.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

    You may need to add a similar line in your web.config. Note that you need to change the "Data Source=.\SQLEXPRESS" instance with the one of your SQL server instance, in order to run the sample. In your case, it may be something like "Kevin\SQLEXPRESS".

    About your second question on how to get at the value, I am not sure if you need it on client-side or server-side. I am sending you a Client-side Programming article from the RadSearchBox Documentation. You can find Server-side Programming documentation there, as well.

    In addition, I am sending you the Client-Side Events and the Server-side Events demos.

    I hope that would solve your issues.

    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top