Ext.Net 1.x_Ext.Net.Combox 实现模糊异步查询

ERP-易飞
易飞ERP系统运维、二次开发、实施
厦门德仔

突然间想到百度和GOOGLE的AJAX模糊查询的功能。那就COMBOX中能不能实现呢?

查看资料

在数据源中多了一个  

            <Proxy>
                            <ext:HttpProxyMethod="POST"Url="Plants.ashx"/>
            </Proxy>

估计是异步的东东。本人才浅

先建立一个

<%@ WebHandler Language="C#" Class="DataHandler" %>

using System;
using System.Web;
using System.Collections.Generic;
using Ext.Net;
using System.Data;

public class DataHandler : IHttpHandler {
public void ProcessRequest(HttpContext context)
    {
        if (!string.IsNullOrEmpty(context.Request["query"]))
        {

            string query = context.Request["query"];

            context.Response.ContentType = "text/json";

            DataTable table = new DAL.UserDAO().WorkNoList(query).Tables[0] ;
          

            List<UserInfo> lst = new List<UserInfo>();

            foreach (DataRow row in table.Rows)
            {

                UserInfo user = new UserInfo();

                user.UserName = Convert.ToString(row["name"]);
                //user.UserId = Convert.ToInt32(row["workno"]);
                user.UserId = Convert.ToString(row["workno"]);
                lst.Add(user);

            }

            string json = Ext.Net.JSON.Serialize(lst);

            context.Response.Write(json);

        }

        else
        {

            context.Response.ContentType = "text/json";

            DataTable table = new DAL.UserDAO().WorkNoList().Tables[0] ;

            List<UserInfo> lst = new List<UserInfo>();

            foreach (DataRow row in table.Rows)
            {

                UserInfo user = new UserInfo();

                user.UserName = Convert.ToString(row["name"]);
                //user.UserId = Convert.ToInt32(row["workno"]);
                user.UserId = Convert.ToString(row["workno"]);
                lst.Add(user);

            }

            string json = Ext.Net.JSON.Serialize(lst);

            context.Response.Write(json);


        }

 

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

public class UserInfo
{
    private string _UserName;

    public string UserName
    {
        get { return _UserName; }
        set { _UserName = value; }
    }
    private string _UserId;

    public string  UserId
    {
        get { return _UserId; }
        set { _UserId = value; }
    }


}

 

 看看效果吧

展开阅读全文

c# combobox如何动态模糊查询

10-19
需求: 每输入字符时combobox.text追加字符,读取数据库并弹出下拉列表,但是text不要不要不要自动选择下拉列表中的项,并且不能清空text,datasouce必须为datatable,因为最后需要得到选取项的(DataRowView)SelectItem.Row。 遇到的问题: 新手问题多,每次droppeddown =true时,都会清空text,并自动选择了第一项,使用textupdate事件,并且text为空或者焦点移动时,因为下拉列表会清空,如果不在开始时进行droppeddown = false,会报index不能为0的错,求大神帮解决一下,以下贴出代码。 private void comboBox1_TextUpdate(object sender, EventArgs e) { this.comboBox1.DroppedDown = false; string s = comboBox1.Text; int newcount = s.Length - i.Length; i += s.Substring(i.Length, newcount); comboBox1.DataSource = null; DataSet ds = new DataSet(); string conntext = "Uid=sa; pwd=sa; database=XZ; server=localhost"; SqlConnection conn = new SqlConnection(conntext); string sql = "select * from Book where BookName like '%" + comboBox1.Text + "%'"; if (comboBox1.Text != string.Empty) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.CommandText = sql; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); ds.Load(dr, LoadOption.OverwriteChanges, "book"); if (ds.Tables["book"].Rows.Count > 0) { this.comboBox1.DataSource = ds.Tables[0]; this.comboBox1.DisplayMember = "bookname"; //this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; //this.comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest; this.comboBox1.DroppedDown = true; //this.comboBox1.DataSource = ds.Tables["book"]; //comboBox1.SelectedIndex = -1; } } this.comboBox1.Text = i; conn.Close(); comboBox1.SelectionStart = comboBox1.Text.Length; Cursor.Current = Cursors.Default; }
©️2020 CSDN 皮肤主题: 鲸 设计师: meimeiellie 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值