百度的模糊查询用MVC开发怎么实现的?例如,输入 网络 这两个字,他会自动加载网络相关的信息??
百度的模糊查询用MVC开发怎么实现的?例如,输入网络这两个字,他会自动加载网络相关的信息??如果信息多的话,也可以像下拉框往下拉??然后点击网络游戏,自动就加载网络游戏的...
百度的模糊查询用MVC开发怎么实现的?例如,输入 网络 这两个字,他会自动加载网络相关的信息??如果信息多的话,也可以像下拉框往下拉??然后点击网络游戏,自动就加载网络游戏的信息?求前台代码??
展开
展开全部
界面
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Mytxt.ascx.cs" Inherits="WebMemberManage.WebUserControl.Mytxt" %>
<script type="text/javascript">
function itemSelected(source, eventArgs)
{
var txtManager = document.getElementById(source.get_element().id); //获得当前编辑的对象
txtManager.value=txtManager.value.split('(')[0];
var a=document.getElementById("<%=lkb_Submit.ClientID %>");
if(a==null)
{
return;
}
a.click();
}
</script>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtManager" runat="server" Width="350px"></asp:TextBox>
<asp:LinkButton
ID="lkb_Submit" runat="server" onclick="lkb_Click"></asp:LinkButton>
<cc1:AutoCompleteExtender ID="txtManager_AutoCompleteExtender" runat="server" TargetControlID="txtManager"
ServicePath="~/MyWebService.asmx" ServiceMethod="GetSimilarMemberByName" MinimumPrefixLength="1"
CompletionSetCount="10" EnableCaching="true" CompletionInterval="5" OnClientItemSelected="itemSelected">
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
界面代码
using System;
namespace WebMemberManage.WebUserControl
{
public delegate void MyDel();
[System.Web.Script.Services.ScriptService]
public partial class Mytxt : System.Web.UI.UserControl
{
/// <summary>
/// 选择完成后触发的事件
/// </summary>
public event MyDel GetText;
protected void lkb_Click(object sender, EventArgs e)
{
if (GetText != null)
GetText();
}
protected void Page_Load(object sender, EventArgs e)
{
}
public string Text
{
get
{
return txtManager.Text;
}
set
{
txtManager.Text = value;
}
}
}
}
webservice
[WebService(Namespace = "MemberManager")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyWebService : System.Web.Services.WebService
{
[WebMethod]
public List<string> GetSimilarMemberByName(string prefixText, int count)
{
List<string> result = new List<string>();
BLLUser bllUser = new BLLUser();
DataTable table = bllUser.GetSimilarMemberByName(prefixText,count);
foreach (DataRow item in table.Rows)
{
result.Add(item["name"].ToString());
}
return result;
}
}
封装
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//首次加载的时候 绑定的方法
}
Mytxt1.GetText += new WebMemberManage.WebUserControl.MyDel(Mytxt1_GetText);
}
void Mytxt1_GetText()
{
//具体的绑定方法
}
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Mytxt.ascx.cs" Inherits="WebMemberManage.WebUserControl.Mytxt" %>
<script type="text/javascript">
function itemSelected(source, eventArgs)
{
var txtManager = document.getElementById(source.get_element().id); //获得当前编辑的对象
txtManager.value=txtManager.value.split('(')[0];
var a=document.getElementById("<%=lkb_Submit.ClientID %>");
if(a==null)
{
return;
}
a.click();
}
</script>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtManager" runat="server" Width="350px"></asp:TextBox>
<asp:LinkButton
ID="lkb_Submit" runat="server" onclick="lkb_Click"></asp:LinkButton>
<cc1:AutoCompleteExtender ID="txtManager_AutoCompleteExtender" runat="server" TargetControlID="txtManager"
ServicePath="~/MyWebService.asmx" ServiceMethod="GetSimilarMemberByName" MinimumPrefixLength="1"
CompletionSetCount="10" EnableCaching="true" CompletionInterval="5" OnClientItemSelected="itemSelected">
</cc1:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
界面代码
using System;
namespace WebMemberManage.WebUserControl
{
public delegate void MyDel();
[System.Web.Script.Services.ScriptService]
public partial class Mytxt : System.Web.UI.UserControl
{
/// <summary>
/// 选择完成后触发的事件
/// </summary>
public event MyDel GetText;
protected void lkb_Click(object sender, EventArgs e)
{
if (GetText != null)
GetText();
}
protected void Page_Load(object sender, EventArgs e)
{
}
public string Text
{
get
{
return txtManager.Text;
}
set
{
txtManager.Text = value;
}
}
}
}
webservice
[WebService(Namespace = "MemberManager")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyWebService : System.Web.Services.WebService
{
[WebMethod]
public List<string> GetSimilarMemberByName(string prefixText, int count)
{
List<string> result = new List<string>();
BLLUser bllUser = new BLLUser();
DataTable table = bllUser.GetSimilarMemberByName(prefixText,count);
foreach (DataRow item in table.Rows)
{
result.Add(item["name"].ToString());
}
return result;
}
}
封装
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//首次加载的时候 绑定的方法
}
Mytxt1.GetText += new WebMemberManage.WebUserControl.MyDel(Mytxt1_GetText);
}
void Mytxt1_GetText()
{
//具体的绑定方法
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询