^, first of all: Sorry for my english =X
I'm creating an autocomplete componente and i'm having some issues.
I'm passing via ajax some parameters to my aspx page.
jQuery Code:
/* AutoComplete */
$(function () {
$('.ACCascata').bind('keyup', function () {
// Criação do apontamento
var tipoObj = $(this).attr("tipo").toString();
$(this).autocomplete({
source: function (request, response) {
$.ajax({
url: "AutoComplete.aspx",
dataType: "json",
data: {
tipo: tipoObj, //Apontamento
q: request.term //Item digitado no input
},
success: function (event, ui) {
response(event);
},
error: function (xhr, ajaxOptions, thrownError) {
//alert(xhr.status);
//alert(thrownError);
}
});
}
});
});
});
.Net code
public class AutocompleteItem
{
private String id;
public String Id
{
get { return id; }
set { id = value; }
}
private String value;
public String Value
{
get { return this.value; }
set { this.value = value; }
}
}
protected void Page_Load(object sender, EventArgs e)
{
switch (Request.QueryString["tipo"])
{
case "pais":
this.BuscaPaises(Request.QueryString["q"]);
break;
case "estado":
this.BuscaEstados(Request.QueryString["q"]);
break;
case "cidade":
this.BuscaCidades(Request.QueryString["q"]);
break;
}
}
private void BuscaPaises(string query)
{
try
{
AcessoDados BuscaLocal = new AcessoDados();
BuscaLocal.OpenConnection();
String SqlSelect = "SELECT ID, Nome FROM Paises Where Nome like '%" + query + "%'";
BuscaLocal.Select(SqlSelect);
//ArrayList resultado = new ArrayList();
ArrayList result = new ArrayList();
while (BuscaLocal.Records.Read())
{
AutocompleteItem autoCompletar = new AutocompleteItem();
autoCompletar.Id = BuscaLocal.Records["ID"].ToString();
autoCompletar.Value = BuscaLocal.Records["Nome"].ToString();
//resultado.Add(autoCompletar);
result.Add(BuscaLocal.Records["Nome"].ToString());
}
BuscaLocal.CloseConnection();
JavaScriptSerializer js = new JavaScriptSerializer();
//string jsonResult = js.Serialize(resultado);
string jsonResult = js.Serialize(result);
Response.Write(String.Format("{0}", jsonResult));
}
catch (Exception falhaSelect)
{
throw falhaSelect;
}
}
Sorry, portuguese =X
the code above "works" but only sends the name (of course, it's the only thing that i'm passing). The commented code (3 lines) is what is giving me pain...
i'm trying send back ID and Name (Nome in portuguese), but i don't know how achieve this.
using :
BAssistance AutoComplete from JÖRN ZAEFFERER .
Asp.Net FrameWork 3.5.