jquery autocompelete

 前台调用:

     $("#CompanyName").autocomplete("../AjaxHandler/GetBranchH.ashx", {
        formatItem: function(row, i,max) {
            var obj =eval("(" + row + ")"); //转换成js对象
            return obj.COMPANYNAME;
        },
        formatResult: function(row) {
            var obj =eval("(" + row + ")"); //转换成js对象
            return obj.COMPANYNAME;
        }
        }).result(function(event, item) {
            var obj = eval("(" +item + ")"); //转换成js对象
            //alert(obj.BRANCHCOMPANYNO);
            var html="";
            $("#department").empty();
            $("#BRANCHCOMPANYNO").val(obj.BRANCHCOMPANYNO);
            $.getJSON("../AjaxHandler/GetByNoDepartmentH.ashx",{Num:obj.BRANCHCOMPANYNO},function(data){
               $.each(data,function(k,v){
                   html+="<option value="+v.DEPID+">"+v.DEPARTMENTNAME+"</option>";
               });
              $("#department").append(html);
            });
            
            //$("#link").attr("href",obj.url);
      });

后台代码:

            string strwhere="BRANCHCOMPANYNO like ‘%"+param+"%‘";
            strwhere += " or COMPANYNAME like ‘%" + param + "%‘";
            strwhere += " or SHORTNAME like ‘%" + param + "%‘";
            DataTable dt= b_Branch.GetList(15,strwhere,"ID").Tables[0];
            
            //JavaScriptSerializer jss = new JavaScriptSerializer();
            //List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();

            //context.Response.Write("[{\"label\":\"博客园\",\"value\":\"cnblogs\"},{\"label\":\"囧月\",\"value\":\"囧月\"}]");

            HttpResponse response = context.Response;
            System.IO.TextWriter writer = response.Output;
            // 注意,必须是标准的 JSON 格式串,必须使用双引号
            //writer.Write("[\"One\", \"Two\", \"Three\"]");
            string strb = "";
            foreach (DataRow dr in dt.Rows)
            {
                //Dictionary<string, object> result = new Dictionary<string, object>();
                foreach (DataColumn dc in dt.Columns)
                {
                    if (dc.ColumnName == "BRANCHCOMPANYNO") {
                        strb+="{BRANCHCOMPANYNO:\"" + dr[dc.ColumnName].ToString() + "\",";
                    }
                    if (dc.ColumnName == "COMPANYNAME")
                    {
                        strb += "COMPANYNAME:\"" + dr[dc.ColumnName].ToString() + "\"}\n";
                        //result.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                    }
                }
                //list.Add(result);
            }
            strb = strb.ToString().TrimEnd(‘\n‘);
            //strb += "]";
            writer.Write(strb);

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。