多重AutoComplete的Textbox

來源:互聯網
上載者:User

目前所見的只是單個autocomplete的文字框,也就是說只能根據文字框的單一內容進行查詢資料,對於比如用分號或其他標點符號隔開的文字不能實現繼續的autocomplete。這裡本人做了個textbox可以根據文字框裡用分號隔開的內容進行查詢,即只根據當前輸入的內容進行查詢,而之前的內容不會影響。並且支援修改,修改之後還在原處插入。具體內容如下:
/*
 * shenba 2008 all right reserved
 * 作者:shenba
 * 控制項名稱:MutiAutoCompleteTextBox
 * 主要功能:實現多重的AutoComplete;
 *               支援,;,;間隔;
 *               支援單個結果按斷行符號後自動添加;
 *               支援修改,修改之後仍在原處添加;
 *               所有操作無重新整理
 * 主要技術:ICallbackEventHandler的實現,以及javascript的應用
 * 使用方法:設定控制項的DataTextField,DataValueField, 實現GetDataSource事件,根據事件參數的Prefix進行查詢,擷取結果,然後繫結控制項.DataTextField是要顯示在下拉框中的欄位,DataValueField是顯示在文字框中的欄位
 */
MutiAutoCompleteTextBox

用法

實現GetDataSource事件
 1protected void mutiAutoCompleteTextBox1_GetDataSource(object sender, Shenba.CustomControl.AutoCompleteArgs e)
 2        {
 3            DataSet ds = new DataSet();
 4            using (SqlConnection con = new SqlConnection(conString))
 5            {
 6                SqlCommand command = new SqlCommand("select [CompanyName] + '_' + [ContactName] Details, [CompanyName] from suppliers1 where CompanyName like @Name", con);
 7                command.Parameters.Add(new SqlParameter("@name", e.Prefix + "%"));
 8                SqlDataAdapter adapter = new SqlDataAdapter(command);
 9                adapter.Fill(ds);
10            }
11            mutiAutoCompleteTextBox1.DataSource = ds.Tables[0];
12            mutiAutoCompleteTextBox1.DataBind();
13        }

目前介面方面的設定還比較欠缺,將繼續更進。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.