PDA

View Full Version : autocomplete textfield data from webservice



chsrinivasgupta
30 Aug 2012, 2:43 AM
hi

i am unable to get data from a web service to combo box and i have to made this combo box as autocomplete field. Please give me the comple code for this. Thanks in advance for help.

tvanzoelen
30 Aug 2012, 4:57 AM
You could have a look at this: http://docs.sencha.com/ext-js/4-1/#!/example/form/forum-search.html

chsrinivasgupta
30 Aug 2012, 5:25 AM
in place of url i hv given webservice path and method name but i an unable to get. Thanks in advance

chsrinivasgupta
30 Aug 2012, 5:37 AM
It is not coming in place of url if we give webservice name and method name can u modify the code available and send me the modified code for my problem ? Thanks in advance

sword-it
30 Aug 2012, 5:38 AM
Hi,

Here is sample example for filling combobox from DB table-

GenresWebService.asmx (webservice)


using System.Web.Script.Serialization; // Add this namespace for serialization

public class GeneresWebService: System.Web.Services.WebService
{
[WebMethod]
public string GetGeneres()
{
SqlConection con = new SqlConection(conectionString);
con.Open();
String sql = "SELECT genre_id, genre_ame FROM generes_movie" ;
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet genres = new DataSet();
da.Fill(genres, "movie_geners");


JavaScriptSerializer jss = new JavaScriptSerializer();
string json = jss.Serialize(genres);
con.Close();

return "{items: " + json + "}";

}
}



SampleForm.js



var movie_genres = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['genre_id', 'genre_name'],
root: 'items'
}),
proxy: new Ext.data.HttpProxy({
url: '../GenresWebService.asmx/GetGenres'
})
})
;var movie_form = new Ext.FormPanel({
url: 'movie-form-submit.aspx',
renderTo: 'myform',
frame: true,
title: 'Movie Information Form',
width: 400,
defaults: {
anchor: '100%'
},
items: [{
xtype: 'combo',
typeAhead :true ,
hiddenName: 'genre',
fieldLabel: 'Genre',
mode: 'remote',
store: movie_genres,
displayField: 'genre_name',
valueField: 'genre_id'
}]});