<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="baidu_Default" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" BehaviorID="AutoCompleteEx"
TargetControlID="TextBox1"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
MinimumPrefixLength="1"
EnableCaching="true"
CompletionSetCount="20"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :">
<Animations>
<OnShow>
<Sequence>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<ScriptAction Script="
// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" />
<Parallel Duration=".4">
<FadeIn />
<Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations> </cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" BehaviorID="AutoCompleteEx"
TargetControlID="TextBox1"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
MinimumPrefixLength="1"
EnableCaching="true"
CompletionSetCount="20"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :">
<Animations>
<OnShow>
<Sequence>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<ScriptAction Script="
// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" />
<Parallel Duration=".4">
<FadeIn />
<Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations> </cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
解决方案 »
- asp.net中能实现像QQ空间那样任意拖放模块吗?
- 感谢推荐一套可多选的日历控件
- asp.NET 前台一个function 后台怎么调用
- 在visual studio 2005中 asp.net 设置中连不上数据库
- |zyciis| 在VS2005添加系统文件网站的时候,运行后他们的地址都为http://localhost:XXXX/Web/Default.aspx 这样是虚拟目录 要网站怎么办
- 如何在 postback网页后,回来,IE窗口的上下滚动条 保存原来的位置?
- 求助!如何实现无刷新跳转
- 郁闷的删除问题.Delete From 表名 Where Id In (@Ids),为什么这样调用时老是提示说 从"Varchar" 向 "Int" 的转换无效??
- xml数据导入sqlserver2005
- asp.net中如何设置鼠标移到GridView行上面后,鼠标变成链接的样式
- 谁有卖论坛+博客的产品啊 最好是支持oracle 的
- 在制作安装文件部署web程序时,如何修改某一文件夹的访问权限和IIS网站的属性
namespace BaiJie.Web
{
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Data;
using System.Collections.Generic; /// <summary>
///AutoComplete 的摘要说明
/// </summary>
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService { public AutoComplete () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string[] GetCompletionList(string prefixText)
{
BJMsgInfo MsgInfo = new BJMsgInfo();
MsgInfo.CompanyName = prefixText;
// DataTable tbl =WebManager.List("select words from searchwords where words like '%"
// + prefixText + "%'");
DataTable dt = WebManager.List(MsgInfo, "", "CompanyName", "&company%", "");
List<string> items = new List<string>();
foreach (DataRow dr in tbl.Rows)
{
items.Add(dr["words"].ToString());
}
return items.ToArray();
}
}
}
帮我看下
我刚才测试没有效果
DataTable tbl =WebManager.List("select words from searchwords where words like '%"
+ prefixText + "%'");
这个数据库
是自己输入的吗?
AutoCompleteExtender控件可以帮你自动填写TextBox控件(在数据库中查找).
属性:
TarGetControlID:指定要让"自动输入完成"扩展器要扩展的TextBox控件ID.
ServicePath:Web服务的位置路径.
ServiceMehod:要调用的Web服务的方法名.方法签名如下:[System.Web.Services.WebMethod]
[System.Web.Script.Service.ScriptMethod]
public string[] GetCompetionList(string prefixText,int count){......}
前台代码:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
MinimumPrefixLength="1" ServiceMethod="GetProductName" ServicePath="WebService.asmx">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
WebService代码:using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Services;//关键程序集引用
using System.Collections.Generic;//关键程序集引用/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]//一定要添加
public class WebService : System.Web.Services.WebService { public WebService () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
[ScriptMethod]
public string[] GetProductName(string prefixText, int count)
{
List<string> suggestions=new List<string>();//声明一泛型集合
SqlConnection con = new SqlConnection("server=.;database=NorthWind;uid=sa;pwd=;");
con.Open();
SqlCommand com = new SqlCommand("select distinct productname from Products where productname like @prefixname order by productname", con);
com.Parameters.Add("@prefixname",SqlDbType.NVarChar).Value=prefixText + "%";
SqlDataReader sdr = com.ExecuteReader();
while (sdr.Read())
{
suggestions.Add(sdr.GetString(0));
}
sdr.close();
con.close();
return suggestions.ToArray();
}
}
AjaxControlToolkit安装&下载
以下是收集关于AjaxControlToolkit安装的一篇文章,感谢原作者AjaxControlToolkit下载http://ajax.asp.net/downloads/default.aspx?tabid=47http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=1425
环境设置如下:下载完 ASPAJAXExtSetup.msi 安装更新后在你的系统盘下的(以C盘为例) 出现这个 文件夹:C:\Program Files\Microsoft asp.NET\ASP.NET 2.0 ajax Extensions\v1.0.61025安装这个后我们就可以创建Asp.net AJAXEnabledWebSite站点了,这其实就是个ajax.net网站的模板。但是我们现在还不能使用微软给我们开发好的ajax控件 。要想知道怎么使用ajax.net控件往下看。下载AjaxControlToolkit ,上面两个一个是带源代码的 一个是不带源代码的toolkit。建议下载带源代码的 toolkit。下载完成后把该文件解压到:C:\Program Files\Microsoft asp.NET\ASP.NET 2.0 ajax Extensions\v1.0.61025\AjaxContronlToolkit\ 双击运行AjaxControlToolkit.sln。用vs2005打开这个sln,编译TemplateVSI这个项目后,把在C:\Program Files\Microsoft asp.NET\ASP.NET 2.0 AJAX Extensions\SampleWebSite\Bin下面生成的AjaxControlToolkit.dll和AjaxControlToolkit.pdb复制到C:\Program Files\Microsoft asp.NET\ASP.NET 2.0 AJAX Extensions\Binaries文件夹下面,这样我们就可以在vs2005中使用ajax.net这些控件了。新建一个Ajax ControlToolkitWebSite 类型的web项目。在工具栏中新添加一个选项卡起名:AjaxControltoolkit在这个选项卡上右键选择项->浏览找到刚才复制过去的AjaxControlToolkit.dll,添加进来。这样我们就ajax.net控件成功引用到vs2005中了 。
Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div> <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="GetCompletionList" ServicePath="AutoComplete.asmx" TargetControlID="TextBox1" CompletionSetCount="10">
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div> <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="GetCompletionList" ServicePath="AutoComplete.asmx" TargetControlID="TextBox1" CompletionSetCount="10">
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
namespace BaiJie.Web
{
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Data;
using System.Collections.Generic; /// <summary>
///AutoComplete 的摘要说明
/// </summary>
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService { public AutoComplete () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string[] GetCompletionList(string prefixText)
{
BJMsgInfo MsgInfo = new BJMsgInfo();
MsgInfo.CompanyName = prefixText;
DataTable dt = WebManager.List(MsgInfo, "", "CompanyName", "&companyname%", "");
List<string> items = new List<string>();
foreach (DataRow dr in dt.Rows)
{
items.Add(dr["CompanyName"].ToString());
}
return items.ToArray();
}
}
}
参考六楼的例子
DataTable dt = WebManager.List(MsgInfo, "", "CompanyName", "&companyname%", "");我的这个段代码就是的啊
根据传过来的prefixText
"&companyname%模糊查询然后返回一个DataTable
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
/// <summary>
///AutoComplete 的摘要说明
/// </summary>
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]//一定要添加
[WebService(Namespace = "http://tempuri.org/")] //[WebService(Namespace = "http://localhost:2459/ZYT/baidu/AutoComplete.asmx")]
public class AutoComplete : System.Web.Services.WebService { public AutoComplete () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText)
{
List<string> suggestions = new List<string>();//声明一泛型集合
SqlConnection con = new SqlConnection(@"Data Source=ZZWLINE\SQLEXPRESS;Initial Catalog=F:\我的单子\200904\项目\ZYT\APP_DATA\BJYZT.MDF;Integrated Security=True;");
con.Open();
SqlCommand com = new SqlCommand("select distinct CompanyName from BJMsgInfo where CompanyName like @prefixname order by CompanyName", con);
com.Parameters.Add("@prefixname", SqlDbType.NVarChar).Value = prefixText + "%";
SqlDataReader sdr = com.ExecuteReader();
while (sdr.Read())
{
suggestions.Add(sdr.GetString(0));
}
sdr.Close();
con.Close();
return suggestions.ToArray();
} }
Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="GetCompletionList" ServicePath="http://localhost:2459/ZYT/baidu/AutoComplete.asmx" TargetControlID="TextBox1" MinimumPrefixLength="1">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
[System.Web.Script.Services.ScriptService()]//一定要添加 public class AutoComplete : System.Web.Services.WebService { public AutoComplete () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string[] GetCompletionList(string prefixText)