前台

<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. .csv导入mysql时出现乱码

  2. cloudera learning2:HDFS

    存入HDFS的文件会按块(block)划分,默认每块128MB.默认1个block还有2个备份.备份增加了数据的可靠性和提高计算效率(数据本地化). HDFS部署可选择不支持HA,也可选择支持HA. ...

  3. jquery easyui tree的全选与反选

    //全选反选 //参数:selected:传入this,表示当前点击的组件 //treeMenu:要操作的tree的id:如:id="userTree" function tree ...

  4. drop表后仍占表空间解决办法

    练习oracle时create了很多表,drop表后select * from tab; 网上找了好些方法,但是好多都适用... SQL>purge recyclebin; 回收站已清空.

  5. ios结构体语法

  6. 浏览器桌面通知--Notification

    前言 最近项目上要用到浏览器桌面通知,之前虽然知道有这个东西,但是一直没有用过,借此机会了解下桌面通知的机制,在此分享下. 1.权限 首先需要明确的是,不是所有网页都可以发桌面通知的,不然不得烦死,那 ...

  7. 360浏览器下载excel问题解决方式

    亲们有没有碰到过今天我遇到的这件事. 如果使用简单的链接.或者get方式提交的表单,去下载excel,那么360浏览器就会有问题. 问题是:它没把我用java生成的excel表格下载,而是去把我的列表 ...

  8. Liunx下的系统负荷

                uptime命令回显中的load average所表示的意思和w命令相似,都是表示过去的1分钟.5分钟和15分钟内进程队列中的平均进程数量. 这里需要注意的是load aver ...

  9. ferret不能创建txt文本--cookiecadger截获不到包

    终于解决了-- 虽然是通宵  又是隔了一天  .但还是解决了. 要/proc/sys/net/ipv4/ip_forward =1 echo 1 > /proc/sys/net/ipv4/ip_ ...

  10. [原创]java WEB学习笔记109:Spring学习---spring中事物管理

    博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱好 ...