目前所見的只是單個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 }
目前介面方面的設定還比較欠缺,將繼續更進。