Http://www.dotnetcurry.com/ShowArticle.aspx? Id = 515
Http://stackoverflow.com/questions/2471166/jquery-autocomplete-jquery-ui-1-8rc3-with-asp-net-web-service
<SCRIPT type = "text/JavaScript"> $ (function () {$ ("# baomingname "). autoComplete ({Source: function (request, response) {$. ajax ({URL: "handler/WebService. asmx/getdata ", data:" {'stdame': '"+ request. term + "'}", datatype: "JSON", type: "Post", contenttype: "application/JSON; charset = gbk2312", datafilter: function (data) {return data;}, success: function (data) {response ($. map (data. d, function (item) {return {value: item. stuname }}))}, error: function (XMLHttpRequest, textstatus, errorthrown) {alert (textstatus) ;}}, select: function (event, UI) {// alert (UI. item. value); $. ajax ({URL: "handler/WebService. asmx/getsinglestu ", data:" {'stdame': '"+ UI. item. value + "'}", datatype: "JSON", type: "Post", contenttype: "application/JSON; charset = gbk2312", datafilter: function (data) {return data;}, success: function (data) {// alert (data. d); var STR = data. d; var JSON = eval (STR); $. each (JSON, function (I) {alert (JSON [I]. stuid); // $ ("# test" example .html (JSON [I]. stuid);}); -------------------------------- the json value of the background activity ----------------------------------------------- // var list = eval (data. d); // For (VAR I = 0; I <list. length; I ++) {// $ ("# test" ).html (list [I]. stuname); //}, error: function (XMLHttpRequest, textstatus, errorthrown) {alert (textstatus) ;}}, minlength: 1 });}); </SCRIPT>
Datatable to JSON
Private string createjsonparameters (datatable DT) {stringbuilder jsonstring = new stringbuilder (); // Exception Handling if (DT! = NULL & DT. rows. count> 0) {jsonstring. append ("{"); jsonstring. append ("D: ["); For (INT I = 0; I <DT. rows. count; I ++) {jsonstring. append ("{"); For (Int J = 0; j <DT. columns. count; j ++) {If (j <DT. columns. count-1) {jsonstring. append (DT. columns [J]. columnname + ":" + "\" "+ dt. rows [I] [J]. tostring () + "\", ");} else if (j = DT. columns. count-1) {jsonstring. append (DT. columns [J]. columnname + ":" + "\" "+ dt. rows [I] [J]. tostring () + "\" ") ;}}/** // * end of string */if (I = DT. rows. count-1) {jsonstring. append ("}");} else {jsonstring. append ("},") ;}} jsonstring. append ("]}"); Return jsonstring. tostring () ;}else {return NULL ;}}