前台

<link rel="stylesheet" type="text/css" href="../css/easyui.css"/>
 <script type="text/JavaScript" src="../js/jQuery-1.7.1.min.js"></script>
 <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
     <script type="text/javascript">
         var vID = "DDLCC";
         $(function () {
             $('#' + vID).combobox({
                 valueField: 'TPrice', //TPrice
                 textField: 'typeName',
                 //注册事件
                 onChange: function (newValue, oldValue) {
                     if (newValue != null) {
                         var thisKey = encodeURIComponent($('#' + vID).combobox('getValue')); //搜索词
                         var thisType = ""; //车辆类型 
                         var urlStr = "AutoComplete.ashx?objType=" + thisType + "&objStr=" + thisKey;
                         $("#" + vID).combobox("reload", urlStr);
                     }
                 },
                 onSelect: function (record) {
                     setValue(record.typeName);                   
                     //document.getElementById("TextBox4").value = record.TPrice;
                     $("#TextBox4").val(record.TPrice);
                 }
             });
         });
         function setValue(vTxt) {
             $('#' + vID).combobox('setValue', vTxt);
         }
    </script>
  <style type="text/css">
   .combo
   { 
   height:15px;
   border:1px  solid #CECCCD;      
   overflow :hidden ;
   }
   .combo .combo-text{
   height:15px;  
   font-size:12px;
   line-height:15px;
   color :#000000;
   }
   .combo .combo-arrow{
 background:#E0ECF9 url('../css/images/combo_arrow.gif') no-repeat 0px 0px;
 width:14px; 
 height:15px;
 overflow:hidden; 
 vertical-align:middle;
 cursor:pointer;
 opacity:0.6;
 filter:alpha(opacity=60);
   } 
 </style>

<select id="DDLCC" class="easyui-combobox" name="DDLCC"  style="width:84px;" data-options="required:true" title="键入搜索查询" >                            
         </select>

后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Newtonsoft.Json;
using System.Text;

namespace used_car.web
{
    /// <summary>
    /// AutoComplete 的摘要说明
    /// </summary>
    public class AutoComplete : IHttpHandler
    {
        protected DataTable dt = null;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            ClearClientPageCache();
            context.Response.ContentType = "text/plain";        
            string strObjTypee = "", strObjStr = "";
             if (context.Request.QueryString["objType"] != null && context.Request.QueryString["objStr"]!=null)
             {
                 strObjTypee = context.Server.UrlDecode(context.Request.QueryString["objType"].ToString());
                 strObjStr = context.Server.UrlDecode(context.Request.QueryString["objStr"].ToString());
                 dt = linkeMaterials(strObjTypee, strObjStr);
                 if (dt != null)
                 {
                     string data2 = JsonConvert.SerializeObject(dt);                    
                     context.Response.Write(data2);
                     context.Response.Flush();
                     context.Response.End();
                 }
             }
        }

public DataTable linkeMaterials(object objType, object objStr)
        {
            DataTable dt = new DataTable();
            if (objStr != null)
            {
                if (!string.IsNullOrWhiteSpace(objStr.ToString()))
                {
                    //left(T11,2)='" + objType + "' or 
                    string strSql = "select top 15  C.T46 as typeName, C.T45 as ID,C.T47 as TPrice from [dbo].[JC79] as C where  T46 like'%" + objStr + "%'";
                    DataSet dsJC97 = Maticsoft.DBUtility.DbHelperSQL.Query(strSql);
                    dt = dsJC97.Tables[0];
                }
            }
            return dt;
        }
        StringBuilder sbJC97 = new StringBuilder("");
        public string linkeMaterials2(object objType, object objStr)
        {
            if (objStr != null)
            {
                if (!string.IsNullOrWhiteSpace(objStr.ToString()))
                {
                    //left(T11,2)='" + objType + "' or 
                    string strSql = "select top 15  C.T46 as 型号名称, C.T47 as 现行价格, C.T45 as ID,C.T11 as 种类编号 from [dbo].[JC79] as C where T46 like'%" + objStr + "%'";
                    DataSet dsJC97 = Maticsoft.DBUtility.DbHelperSQL.Query(strSql);
                    if (dsJC97 != null)
                    {
                        DataTable dtJC97 = dsJC97.Tables[0];
                        int dtCount = dtJC97.Rows.Count;
                        if (dtCount > 0)
                        {
                            for (int i = 0; i < dtCount; i++)
                            {
                                sbJC97.Append("{ typeName: \"" + dtJC97.Rows[i]["型号名称"] + "\",ID: \"" + dtJC97.Rows[i]["ID"] + "\",Price: \"" + dtJC97.Rows[i]["现行价格"] + "\",ZL: \"" + dtJC97.Rows[i]["种类编号"] + "\"}");
                                if (i != (dtCount - 1))//如果不是最后一个
                                {
                                    sbJC97.Append(",");
                                }
                            }
                        }

}
                }
            }

return sbJC97.ToString();
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        public static void ClearClientPageCache()
        {
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.Expires = 0;
            HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            HttpContext.Current.Response.AddHeader("pragma", "no-cache"); HttpContext.Current.Response.AddHeader("cache-control", "private"); HttpContext.Current.Response.CacheControl = "no-cache";
        }
    }
}

easyUI-combobox 动态绑定数据源的更多相关文章

  1. easyui combobox点击输入框弹出下拉框

    由于easyui combobox需要点击下拉箭头才能下拉,不能像select标签那样点击输入框就下拉,所以觉得不太方便,查看了一下,combobox弹出框是一个div,原本想在他的输入框的点击事件中 ...

  2. jQuery easyui combobox获取值|easyui-combobox获取多个值

    Query easyui combobox事例:            name="language"             data-options="        ...

  3. easyui combobox onSelect事件

    easyui combobox 没有onchange事件,只有onSelect事件 1 $(function () { $('#Select6').combobox({ onSelect: funct ...

  4. jquery easyui combobox 级联及触发事件,combobox级联

    jquery easyui combobox 级联及触发事件,combobox级联 >>>>>>>>>>>>>>&g ...

  5. Easyui combobox onChange事件

    Easyui combobox onChange事件: 注册事件: $(function () { $('#cc_id').combobox({ onChange: function (newValu ...

  6. JQuery EasyUI Combobox的onChange事件

    html中的select 的change事件 <select id="consult_province" name="consult_province" ...

  7. 关于easyui combobox下拉框实现多选框的实现

    好长时间没有更博了,一是因为最近真的比较忙,二是因为自己是真的偷懒了,哈哈 好啦,这篇博客主要是总结一些关于easyui combobox下拉框实现多选框的实现,包括前台界面的展示,和后台对数据的获取 ...

  8. easyui combobox下拉框复制后再禁用,点击不会出现下拉框

    easyui combobox下拉框禁用,点击不会出现下拉框 需要做到,在给easyui combobox赋值后,再禁用easyui combobox 解决办法: $("#time-sele ...

  9. easyui combobox开启搜索自动完成功能

    combo.json [{ "id":-1, "text":" ", "spell":"" },{ ...

  10. 表单(上)EasyUI Form 表单、EasyUI Validatebox 验证框、EasyUI Combobox 组合框、EasyUI Combo 组合、EasyUI Combotree 组合树

    EasyUI Form 表单 通过 $.fn.form.defaults 重写默认的 defaults. 表单(form)提供多种方法来执行带有表单字段的动作,比如 ajax 提交.加载.清除,等等. ...

随机推荐

  1. mongodb数据库迁移

    如果遇到权限问题,终极解决办法:关掉权限! 如:assertion: 18 { ok: 0.0, errmsg: "auth failed", code: 18 }等错误

  2. k8s入门系列之guestbook快速部署

    k8s集群以及一些扩展插件已经安装完毕,本篇文章介绍一下如何在k8s集群上快速部署guestbook应用. •实验环境为集群:master(1)+node(4),详细内容参考<k8s入门系列之集 ...

  3. Webstorm功能详解及插件推荐

    Web前端开发神器--Webstorm不用多介绍,强大的智能提示只是它的一个功能特性,它还具有许多有用的特性,比如版本控制.本地历史.即时模板等.Webstorm还内置了对 SASS.NodeJS.C ...

  4. CentOS 7 安装 nginx

    一.安装nginx依赖lib库: 1.yum install gcc-c++ -y 2.yum install pcre pcre-devel -y 3.yum install zlib zlib-d ...

  5. c++防止客户端多开巧妙代码

    在读OBS源码时看到一个比较有意思的关于防止用户多开程序的写法,简单有效,记录下 //make sure only one instance of the application can be ope ...

  6. Socket与Http通信

    HTTP(超文本传输协议): HTTP是应用层协议,主要用于解决数据包装的问题. HTTP协议是建立在TCP协议之上的一种应用. HTTP连接最显著的特点是客户端发送的每次请求都需要服务器回送响应,在 ...

  7. DOM的概念(1)

    什么是DOM? 通过 JavaScript,您可以重构整个HTML文档.您可以添加.移除.改变或重排页面上的项目.要改变页面的某个东西,JavaScript就需要对HTML文档中所有元素进行访问的入口 ...

  8. HDU 5458 Stability(双连通分量+LCA+并查集+树状数组)(2015 ACM/ICPC Asia Regional Shenyang Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connecte ...

  9. Hdu 1081 To The Max

    To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  10. paper 124:【转载】无监督特征学习——Unsupervised feature learning and deep learning

    来源:http://blog.csdn.net/abcjennifer/article/details/7804962 无监督学习近年来很热,先后应用于computer vision, audio c ...