前台

<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. Ionic2 开发环境搭建

    Ionic2开发环境要求: Nodejs V4.5.0 Nodejs自带 Npm V2.15.9 同上 Ionic V2.1.0 安装最新ionic即可 Angular2 V2正式版 同上 说明:以上 ...

  2. LL(1)文法

    <源程序>→<外部声明>|<外部声明><函数体> <外部申明>→<头文件><函数声明>|其他声明 <函数体&g ...

  3. LVM 'Can’t open /dev/sdb1 exclusively. Mounted filesystem?' Problem

    服务器做mysql时候,添加的新磁盘做lvm时候,创建物理卷报错 saltstack_s:/proc/scsi # cat /proc/partitions major minor #blocks n ...

  4. logstash redis kafka传输 haproxy日志

    logstash 客户端收集 haproxy  tcp日志 input { file { path => "/data/haproxy/logs/haproxy_http.log&qu ...

  5. SVN迁项目

    next -> 做为新项目检出,finish -> next -> finish -> 否,是

  6. lua自定义迭代器

    迭代器 http://www.tutorialspoint.com/lua/lua_iterators.htm 迭代器能够让你遍历某个集合或者容器中的每一个元素. 对于lua来说, 集合通常指代 ta ...

  7. 关于JS嵌套点击事件的问题。

    $().click() 是点击命令$().click(function(){代码}) 是绑定click事件,并不会直接运行.所以在嵌套的时候就有可能出现重复绑定的问题.下面是使用jsonp跨站访问代码 ...

  8. Java被忽略的基本知识(二)

    14.字符串的内容不可改变,不能修改某个下标的字符值.字符串之间的"+"连接是通过"断开--再连接",修改变量的栈中的引用地址指向. 15.对于数组.类(类的属 ...

  9. SourceInsight阅读Python---张子芳

    首先从http://www.sourceinsight.com/public/languages/下载Python的配置文件Python.CLF ,然后对SourceInsight作如下配置: (1) ...

  10. ios 缺少合规证明

    现在app上传到appStore的时候,项目中如果出现加密,状态栏是:缺少合规证明. 解决的方法是在Info.plist文件中添加:ITSAppUsesNonExemptEncryption 设置为N ...