AutoComplete模糊查询匹配关联控件的问题
一个页面上有两个TextBox框,分别是任务编号TextBox和任务名称TextBox
数据库表tableC
Id OrderNo(任务编号) OrderName(任务名称)
1 201310120001 任务名称1
2 201310120002 任务名称2
前台页面:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
//任务编号TextBox <asp:TextBox ID="txt_OrderNo" runat="server" autocomplete="off" Width="300"></asp:TextBox>
<cc1:AutoCompleteExtender ID="autoComplete1" runat="server" CompletionInterval="1000"
CompletionSetCount="12" EnableCaching="true" MinimumPrefixLength="0" ServiceMethod="GetList"
ServicePath="WebService1.asmx" TargetControlID="txt_OrderNo">
</cc1:AutoCompleteExtender>
<script type="text/javascript">
var frm = document.getElementById("aspnetForm");
if (frm) {
frm.onsubmit = function() { return false; };
}
</script> </div>
//任务名称TextBox
<asp:TextBox id="txt_OrderName" runat="server" ></asp:TextBox>
public string[] GetList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
Random random = new Random();
List<string> items = new List<string>(count);
string str7="";
string str2="";
string strSql = "select * from tableC ";
DataTable mytable = rdtable(strSql);
if (mytable.Rows.Count > 0)
{
for (int a = 0; a < mytable.Rows.Count; a++)
{
if (a != mytable.Rows.Count-1)
{
str7 += mytable.Rows[a]["OrderNo"].ToString() + ",";
str2 += mytable.Rows[a]["OrderName"].ToString() + ",";
}
else if (a == mytable.Rows.Count - 1)
{
str7 += mytable.Rows[a]["OrderNo"].ToString();
str7 += mytable.Rows[a]["OrderName"].ToString();
}
}
}
string[] strOrderNo = str7.Split(',');
string[] strOrderName = str2.Split(',');
for (int i = 0; i < strOrderNo.Length; i++)
{
if (strOrderNo[i].IndexOf(prefixText) >= 0)
{
items.Add(strOrderNo[i]);
}
}
return items.ToArray();
}
[解决办法]
http://download.csdn.net/detail/lifetimeus/3349813