How to return the value of an ID when selecting a record from an auto complete

1

Good afternoon. Reformulating my doubt. As I said I'm doing a sales site in asp.net. I tried to create a search engine, Google style and Facebook, which will filter the results. I discovered that in ASP.NET it would be very tricky, so I got the hint of using a jquery component, the autocomplete. Using this code below, autocomplete sends the data to my handler class, and there it will filter and return me the possible products the user is searching for. My problem is the time the user selects one of the records that the autocomplete displays. I need to get the ID of that particular record to redirect to the correct page. The problem is that I can not get this ID. I would like to know if the error is in my Handler class, or in jquery. I do not know if I have to assign my Id to a value for jquery to read, and if I have I do not know which part to assign.

Here is the HANDLER code

using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Script.Serialization;

namespace Demo
{
    public class StudentHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string term = context.Request["term"] ?? "";
            List<string> listProds = new List<string>();

            string cs =     ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using(SqlConnection con = new SqlConnection(cs))
        {
            SqlCommand cmd = new SqlCommand("usp_pesquisar_produtos", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter()
            {
                ParameterName = "@pesquisa",
                Value = term
            });
            con.Open();
            SqlDataReader rdr = cmd.ExecuteReader();
            while(rdr.Read())
            {
                listProds.Add(rdr["codigo"].ToString());
                listProds.Add(rdr["Descricao"].ToString());
            }
        }

        JavaScriptSerializer js = new JavaScriptSerializer();
        context.Response.Write(js.Serialize(listProds));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

}

And the Asp.Net code

  <%@ Page Language="C#" AutoEventWireup="true"
     CodeBehind="WebForm1.aspx.cs"
     Inherits="Demo.WebForm1" %>
   <!DOCTYPE html>
   <html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
    <title></title>
    <script src="jquery-1.11.2.js"></script>
    <script src="jquery-ui.js"></script>
    <link href="jquery-ui.css" rel="stylesheet" />
    <script type="text/javascript">
        $(document).ready(function () {
            $('#txtName').autocomplete({
            source: 'StudentHandler.ashx'
        });
        });
    </script>
    </head>
     <body style="font-family: Arial">
    <form id="form1" runat="server">
        Student Name :
        <asp:TextBox ID="txtName" runat="server">
        </asp:TextBox>
      </form>
     </body>
     </html>
    
asked by anonymous 15.08.2016 / 19:40

0 answers