单独运行 asmx文件时能从数据库读取结果,但是运行aspx文件后,就出现不了结果,也不提示错误。不知道怎么回事,请大侠们帮助! 附上代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;一,autowebyuebao.asmx文件
/// <summary>
///autowebyuebao 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
//[System.Web.Script.Services.ScriptService]
public class autowebyuebao : System.Web.Services.WebService
{ public autowebyuebao ()
{ //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string[] GetSearchTerm(string prefixText, int count)
{
DataGg data = new DataGg();
if (count == 0)
{
count = 10;
}
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlServices"].ConnectionString))
{
SqlDataAdapter sda = new SqlDataAdapter("select distinct ([LSWLZD_LBBH]+' '+[LSWLZD_WLMC]) from [lc0019999].[LSWLZD] where [LSWLZD_WLMC] like '%" + prefixText + "%'", connection);
DataSet ds = new DataSet();
sda.Fill(ds);
List<string> list = new List<string>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{ list.Add(ds.Tables[0].Rows[i][0].ToString());
}
return list.ToArray();
}
}
}
二、客户端页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Texyboxaspx.aspx.cs" Inherits="Texyboxaspx" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" 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:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
ServicePath="~/autowebyuebao.asmx" ServiceMethod="GetSearchTerm" Enabled="True"
TargetControlID="TextBox2" MinimumPrefixLength="1"
CompletionInterval="300" >
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
PS:是最简单的那种 文本框动态模糊下拉菜单,类似于百度,不知道为什么没结果,是不是和我的新建的项目有关?新建的项目是website不是webapplication,在webapplication项目下 是好用的,没出现问题。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;一,autowebyuebao.asmx文件
/// <summary>
///autowebyuebao 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
//[System.Web.Script.Services.ScriptService]
public class autowebyuebao : System.Web.Services.WebService
{ public autowebyuebao ()
{ //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string[] GetSearchTerm(string prefixText, int count)
{
DataGg data = new DataGg();
if (count == 0)
{
count = 10;
}
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlServices"].ConnectionString))
{
SqlDataAdapter sda = new SqlDataAdapter("select distinct ([LSWLZD_LBBH]+' '+[LSWLZD_WLMC]) from [lc0019999].[LSWLZD] where [LSWLZD_WLMC] like '%" + prefixText + "%'", connection);
DataSet ds = new DataSet();
sda.Fill(ds);
List<string> list = new List<string>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{ list.Add(ds.Tables[0].Rows[i][0].ToString());
}
return list.ToArray();
}
}
}
二、客户端页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Texyboxaspx.aspx.cs" Inherits="Texyboxaspx" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" 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:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
ServicePath="~/autowebyuebao.asmx" ServiceMethod="GetSearchTerm" Enabled="True"
TargetControlID="TextBox2" MinimumPrefixLength="1"
CompletionInterval="300" >
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
PS:是最简单的那种 文本框动态模糊下拉菜单,类似于百度,不知道为什么没结果,是不是和我的新建的项目有关?新建的项目是website不是webapplication,在webapplication项目下 是好用的,没出现问题。
解决方案 »
- C#验证码问题 提示未能未将对象引用设置到对象的实例
- vs 2010链接数据库失败
- 求助:谁有苏鹏讲师的播客《PETSHOP与N层架构》,
- .net 中自动打开doc,pdf,excel文件
- 在线等。。。急求TextBox的滚动条。。怎么样使他在最下面呀。。
- 请教!在线等待!!!!!!!!!!!!
- 如何在Attribute。add(“onblur”,“check1()”) 添加一个方法 check2()
- DataBinder.Eval(Container, "DataItem.strValue")数据显示问题
- sql 問題,看大家有什麼好的方法(急!!!!!!!!!在線啊)
- QQ第三方登陆 登陆成功后回调地址页面自动关闭的问题
- 小弟刚学ADO.NET,进来问个问题
- 怎么能解决不同网站间布局不兼容的问题啊?
- <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<string>0148 铁丝网</string>
<string>0102 铁丝</string>
<string>0102 镀锌铁丝</string>
</ArrayOfString>这是单独运行asmx文件时的结果,但是在aspx页面上运行,在Textbox上输入文字后,没有出现下拉猜到模糊查询,不知道是为什么,很疑惑!
下面是网上找的一个例子04.<asp:TextBox ID="txtTo" runat="server" Width="500px" AutoPostBack="True"></asp:TextBox>
05.<cc1:AutoCompleteExtender ID="AutoCompleteExtenderSearch"
06. MinimumPrefixLength="1"//这是设置输入几个字符才开始调用搜索
07. CompletionInterval="10"
08. runat="server"
09. EnableCaching="true"
10. ServicePath="AutoCompleteSend.asmx"//这是Web Services的路径
11. ServiceMethod="GetToAddress"//这是处理搜索的Web Services下的一个方法
12. TargetControlID="txtTo">//这是对应的TextBox
13.</cc1:AutoCompleteExtender> namespace MySystem.Email
24.