您的位置:首页 > 其它

ajax自动搜索功能

2011-06-01 16:00 120 查看
页面:
<asp:TextBox ID="txt_place" runat="server" class="inputkprice"></asp:TextBox>
<cc1:AutoCompleteExtender ID="txt_place_AutoCompleteExtender" runat="server" DelimiterCharacters=""
ServicePath="" ServiceMethod="GetCarCompletionList" UseContextKey="True" MinimumPrefixLength="1"
TargetControlID="txt_place">
</cc1:AutoCompleteExtender>

后台:
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCarCompletionList(string prefixText, int count, string contextKey)
{
ObjModelDataSource<CAR_加油卡> obj = new ObjModelDataSource<CAR_加油卡>(CAR_加油卡.DBNAME, count, CAR_加油卡.COL_办卡地点 + " like '%" + prefixText + "%'");
string[] str = null;
if (obj != null && obj.Count > 0)//obj.DataObjectSource.Tables[0].Rows.Count=obj.Count(但是obj.Count会有问题)
{
str = new string[obj.GetCount()];
int nN = 0;
foreach (CAR_加油卡 item in obj)
{
str[nN] = item.办卡地点;
nN++;
}
}
return str;
}

/// <summary>
/// 司机姓名查询
/// </summary>
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetDriverName(string prefixText, int count, string contextKey)
{
ObjModelDataSource<CAR_司机资料> obj = new ObjModelDataSource<CAR_司机资料>(CAR_司机资料.DBNAME, count, "司机姓名 like '%" + prefixText + "%'");
string[] str = null;
if (obj != null && obj.DataObjectSource.Tables[0].Rows.Count > 0)
{
str = new string[obj.DataObjectSource.Tables[0].Rows.Count];
int nN = 0;
foreach (CAR_司机资料 item in obj)
{
str[nN] = item.司机姓名;
nN++;
}
}
return str;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: