index.aspx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index"%>
<%@ Register Assembly="AjaxControlToolkit20" Namespace="AjaxControlToolkit20" TagPrefix="cc1" %>
<%@ Register Src="~/usr_control/daohangtu.ascx" TagName="daohangtu" TagPrefix="daohangtu"%>
<%@ Register Src="~/usr_control/daohanglan.ascx" TagName="daohanglan" TagPrefix="daohanglan"%>
<!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>
<title>首页</title>
<link href="css/index.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
body,td,th
{
font-family: 宋体;
margin:4px 4px 4px 4px;
}
.STYLE3
{
font-family: "新宋体";
color: #FF6600;
}
a
{
text-decoration:none;
}
.sousuo
{
width:1257px;
height:90px;
background-color:#f60;
position:absolute;
top:130px;
left:0px;
font-color:white;
text-align:center;
}
</style>
</head>
<body>
<form id="Form" runat="server" action="#" method="post">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="release">
</cc1:ToolkitScriptManager>
<div><daohangtu:daohangtu Id="daohangtu" runat="server"></daohangtu:daohangtu></div>
<div class="sousuo">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate >
<asp:TextBox runat="server" ID="keyword" Width="260px" Height="22px" BackColor="white"></asp:TextBox>
<asp:Button Text="搜索" ID="search" runat="server" Height="30px" OnClick="search_Click" />
<cc1:AutoCompleteExtender
CompletionListElementID="mydrop"
ID="AutoCompleteExtender1"
ServicePath="WebServiceAutoCompleteExtender.asmx"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="12"
ServiceMethod="Get"
TargetControlID="keyword"
MinimumPrefixLength="1"
runat="server">
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
WebServiceAutoCompleteExtender.asmx页面
<%@ WebService Language="C#" CodeBehind="~/App_Code/WebServiceAutoCompleteExtender.cs" Class="WebServiceAutoCompleteExtender" %>
WebServiceAutoCompleteExtender.cs页面using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// WebServiceAutoCompleteExtender 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebServiceAutoCompleteExtender : System.Web.Services.WebService { public WebServiceAutoCompleteExtender () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string[] Get(string prefixText, int count)
{
Produce p = new Produce();
System.Data.DataTable dt = p.GetProduce2(prefixText, count.ToString()).Tables[0];
string[] result = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
result.SetValue(dt.Rows[i][0].ToString(), i);
}
return result;
}
}produce.cs页面using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
public class Produce
{
public SqlConnection GetConn()
{
string str="Data Source=WANGQINGSONG;Database=yishizhuxing;User id=wangyuhua;pwd='12345678'";
SqlConnection sqlcon=new SqlConnection(str);
return sqlcon;
}
public DataSet GetProduce2(string name, string count)
{
string nameLength = Convert.ToString(name.Length); //输入的长度 return GetDS("SELECT top " + count + " [prod_name]] FROM produce WHERE left(ltrim([prod_name]])," + nameLength + ")='" + name + "'");
}
}为什么不能实现类似百度下拉列表呢??请教各位。。我是初学者,谢谢。。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index"%>
<%@ Register Assembly="AjaxControlToolkit20" Namespace="AjaxControlToolkit20" TagPrefix="cc1" %>
<%@ Register Src="~/usr_control/daohangtu.ascx" TagName="daohangtu" TagPrefix="daohangtu"%>
<%@ Register Src="~/usr_control/daohanglan.ascx" TagName="daohanglan" TagPrefix="daohanglan"%>
<!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>
<title>首页</title>
<link href="css/index.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
body,td,th
{
font-family: 宋体;
margin:4px 4px 4px 4px;
}
.STYLE3
{
font-family: "新宋体";
color: #FF6600;
}
a
{
text-decoration:none;
}
.sousuo
{
width:1257px;
height:90px;
background-color:#f60;
position:absolute;
top:130px;
left:0px;
font-color:white;
text-align:center;
}
</style>
</head>
<body>
<form id="Form" runat="server" action="#" method="post">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="release">
</cc1:ToolkitScriptManager>
<div><daohangtu:daohangtu Id="daohangtu" runat="server"></daohangtu:daohangtu></div>
<div class="sousuo">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate >
<asp:TextBox runat="server" ID="keyword" Width="260px" Height="22px" BackColor="white"></asp:TextBox>
<asp:Button Text="搜索" ID="search" runat="server" Height="30px" OnClick="search_Click" />
<cc1:AutoCompleteExtender
CompletionListElementID="mydrop"
ID="AutoCompleteExtender1"
ServicePath="WebServiceAutoCompleteExtender.asmx"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="12"
ServiceMethod="Get"
TargetControlID="keyword"
MinimumPrefixLength="1"
runat="server">
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
WebServiceAutoCompleteExtender.asmx页面
<%@ WebService Language="C#" CodeBehind="~/App_Code/WebServiceAutoCompleteExtender.cs" Class="WebServiceAutoCompleteExtender" %>
WebServiceAutoCompleteExtender.cs页面using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// WebServiceAutoCompleteExtender 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebServiceAutoCompleteExtender : System.Web.Services.WebService { public WebServiceAutoCompleteExtender () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string[] Get(string prefixText, int count)
{
Produce p = new Produce();
System.Data.DataTable dt = p.GetProduce2(prefixText, count.ToString()).Tables[0];
string[] result = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
result.SetValue(dt.Rows[i][0].ToString(), i);
}
return result;
}
}produce.cs页面using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
public class Produce
{
public SqlConnection GetConn()
{
string str="Data Source=WANGQINGSONG;Database=yishizhuxing;User id=wangyuhua;pwd='12345678'";
SqlConnection sqlcon=new SqlConnection(str);
return sqlcon;
}
public DataSet GetProduce2(string name, string count)
{
string nameLength = Convert.ToString(name.Length); //输入的长度 return GetDS("SELECT top " + count + " [prod_name]] FROM produce WHERE left(ltrim([prod_name]])," + nameLength + ")='" + name + "'");
}
}为什么不能实现类似百度下拉列表呢??请教各位。。我是初学者,谢谢。。
解决方案 »
- 结合.net的例子讲一下线程与进程
- 救命啊,一段导致IIS崩溃的代码.帮我看看为什么会这样啊~~~
- 怎么用.net读取一个.txt的文本文件,并将读出的内容存入Oracle9I数据库中~!急!在线等!
- 求助!“Could not find stored procedure 'GetNewTeacherList'.”
- 下拉框
- 推荐论坛:www.coderpub.com
- 各位大哥,我遇到一上费解的问题:
- dataset导入数据库
- 请熟悉用户控件的朋友进来喝杯茶,聊个问题~~~~~~~~~~~~
- 用水晶报表中Text Object 显示数据的问题!急待!!
- 【讨论】一个页面有20多个Js和Css, 怎样提高加载速度?欢迎各位前来围观!
- 来位大神来帮我看看啊!
http://bbs.51cto.com/thread-555663-1.html自动完成 -- AutoComplete控件