ASP.NET网页中怎么实现如图功能? 5
当在文本框内输入内容的时候,显示模糊查询结果;查询的数据是从sqlserver数据库里面获取的;最好能给我点启示;...
当在文本框内输入内容的时候,显示模糊查询结果;
查询的数据是从sql server 数据库里面获取的;
最好能给我点启示; 展开
查询的数据是从sql server 数据库里面获取的;
最好能给我点启示; 展开
5个回答
展开全部
先百度搜索
AjaxControlToolkit.DLL
下载下来
1 添加AjaxControlToolkit.DLL引用
2 添加web服务 在web服务类文件中去掉[System.Web.Script.Services.ScriptService]前面注释
3 添加注册<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
4 工具箱 选择项 选AjaxControlToolkit.DLL 使用AutoCompleteExtender控件
<!--ServiceMethod="方法名" ServicePath="web服务文件" -->
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1"
runat="server" CompletionSetCount="5" MinimumPrefixLength="1"
CompletionInterval="100" ServicePath="SearchAjax.asmx" TargetControlID="TextBox1"
ServiceMethod="SearchNameList">
</cc1:AutoCompleteExtender>
AjaxControlToolkit.DLL
下载下来
1 添加AjaxControlToolkit.DLL引用
2 添加web服务 在web服务类文件中去掉[System.Web.Script.Services.ScriptService]前面注释
3 添加注册<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
4 工具箱 选择项 选AjaxControlToolkit.DLL 使用AutoCompleteExtender控件
<!--ServiceMethod="方法名" ServicePath="web服务文件" -->
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1"
runat="server" CompletionSetCount="5" MinimumPrefixLength="1"
CompletionInterval="100" ServicePath="SearchAjax.asmx" TargetControlID="TextBox1"
ServiceMethod="SearchNameList">
</cc1:AutoCompleteExtender>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个是很简单的ajax功能,你去找找相关的资料就知道了
vs里也有控件,不过要下载,AjaxControlToolkit
名字是这个,具体版本就看你的vs是什么版本了,有05 08的,10的不知道出了没有
vs里也有控件,不过要下载,AjaxControlToolkit
名字是这个,具体版本就看你的vs是什么版本了,有05 08的,10的不知道出了没有
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ajax
1.根据你输入的值查询数据库(通过JS中的onchange事件触发事件查询数据库)
2.找出相应的数据返回(返回字符串给JS,JS组装数据到div中)
3.通过CSS来控制数据的样式(显示)
1.根据你输入的值查询数据库(通过JS中的onchange事件触发事件查询数据库)
2.找出相应的数据返回(返回字符串给JS,JS组装数据到div中)
3.通过CSS来控制数据的样式(显示)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace ajaxselect
{
/**////
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
private void Page_Load(object sender, System.EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(WebForm1));
if (!Page.IsPostBack)
{
this.TextBox1.Attributes.Add("onchange", "cityResult();");
this.DropDownList1.Attributes.Add("onclick", "getData();");
}
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**////
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
GetCityList#region GetCityList
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public DataSet GetCityList(int provinceid)
{
string sql = "select * from city where father like %" + provinceid + "%";
return GetDataSet(sql);
}
#endregion
GetDataSet#region GetDataSet
public static DataSet GetDataSet(string sql)
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlDataAdapter sda = new SqlDataAdapter(sql, ConnectionString);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
#endregion
}
}
测试数据库脚本
CREATE TABLE [dbo].[city](
[id] [int] NOT NULL,
[cityID] [nvarchar](6) COLLATE Chinese_PRC_CI_AS NULL,
[city] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[father] [nvarchar](6) COLLATE Chinese_PRC_CI_AS NULL,
CONSTRAINT [PK_city] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace ajaxselect
{
/**////
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
private void Page_Load(object sender, System.EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(WebForm1));
if (!Page.IsPostBack)
{
this.TextBox1.Attributes.Add("onchange", "cityResult();");
this.DropDownList1.Attributes.Add("onclick", "getData();");
}
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/**////
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
GetCityList#region GetCityList
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public DataSet GetCityList(int provinceid)
{
string sql = "select * from city where father like %" + provinceid + "%";
return GetDataSet(sql);
}
#endregion
GetDataSet#region GetDataSet
public static DataSet GetDataSet(string sql)
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlDataAdapter sda = new SqlDataAdapter(sql, ConnectionString);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
#endregion
}
}
测试数据库脚本
CREATE TABLE [dbo].[city](
[id] [int] NOT NULL,
[cityID] [nvarchar](6) COLLATE Chinese_PRC_CI_AS NULL,
[city] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[father] [nvarchar](6) COLLATE Chinese_PRC_CI_AS NULL,
CONSTRAINT [PK_city] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询