欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net AutoCompleteExtender的一个简单例子代码

程序员文章站 2024-03-09 10:18:11
复制代码 代码如下: &l...
复制代码 代码如下:

<asp:textbox id="txttempscenic" runat="server"></asp:textbox>
<ajax:autocompleteextender id="txttempscenic_autocompleteextender" runat="server" behaviorid="autocompleteex" delimitercharacters="" enabled="true" servicepath="~/webservice/autocomplete.asmx" servicemethod="getscenic" targetcontrolid="txttempscenic" completioninterval="500" completionsetcount="20" enablecaching="true" minimumprefixlength="1"></ajax:autocompleteextender>


autocomplete.asmx
复制代码 代码如下:

<%@ webservice language="c#" codebehind="~/app_code/autocomplete.cs" class="autocomplete" %>


autocomplete.cs
复制代码 代码如下:

using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.services;
using system.data;

/// <summary>
///add by ahuinan
/// </summary>
[webservice(namespace = "http://tempuri.org/")]
[webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]
//若要允许使用 asp.net ajax 从脚本中调用此 web 服务,请取消对下行的注释。
[system.web.script.services.scriptservice]
public class autocomplete : system.web.services.webservice
{


public autocomplete()
{

//如果使用设计的组件,请取消注释以下行
//initializecomponent();
}

[webmethod]
public string helloworld()
{
return "hello world";
}


//获得景区
[webmethod]
public string[] getscenic(string prefixtext,int count)
{

et_erp.bll.erp_scenicarea b_scenicarea = new et_erp.bll.erp_scenicarea();
string strwhere = " sa_name like '" + prefixtext + "%' and sa_isdel = 0";

dataset ds = b_scenicarea.select(" top "+count+" sa_name", strwhere);

count = ds.tables[0].rows.count;

string[] array = new string[count];
for (int i = 0; i < count; i++)
{
array[i] = ds.tables[0].rows[i]["sa_name"].tostring();
}

return array;
}
}