具有gridview的自动完成文本框 [英] autocomplete textbox with gridview

查看:132
本文介绍了具有gridview的自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,英语不好.我是Asp.net的新手.我有一个自动完成的带有数据库的文本框.该数据库有5个列.如果我在自动完成文本框中按名称搜索,则会在gridview上显示相应的其余字段.就像google一样,你能帮我一个忙吗?

Sorry for poor english.Am new to Asp.net.I have an autocomplete textbox with database. The database have 5 coloumns. If i search by name in autocomplete textbox,corresponding remaining fields are display on gridview.It is like as google Can u help me any one.

推荐答案

使用此链接

http://csharpdotnetfreak.blogspot.com/2009/01/ajax-autocomplete-textbox- gridview.html [ ^ ]
use this link

http://csharpdotnetfreak.blogspot.com/2009/01/ajax-autocomplete-textbox-gridview.html[^]


使用系统;
使用System.Collections.Generic;
使用System.Web.Services;
使用System.Data.SqlClient;
使用System.Configuration;
使用System.Data;
[WebService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
公共类AutoComplete:WebService
{
公共AutoComplete()
{
}

[WebMethod]
公共字符串[] GetCompletionList(字符串prefixText,整数计数)
{
如果(count == 0)
{
计数= 10;
}
DataTable dt = GetRecords(prefixText);
List< string> items = new List< string>(count);

for(int i = 0; i< dt.Rows.Count; i ++)
{
字符串strName = dt.Rows [i] [0] .ToString();
items.Add(strName);
}
返回items.ToArray();
}

公用DataTable GetRecords(string strName)
{
字符串strConn = ConfigurationManager.ConnectionStrings
["DatabaseConnectionString"].ConnectionString;
SqlConnection con =新的SqlConnection(strConn);
SqlCommand cmd =新的SqlCommand();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@ Name",strName);
cmd.CommandText =
从测试中选择名称,其中名称类似于''%''+ @ Name +''%''";
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter =新的SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
返回objDs.Tables [0];
}
}
using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
[WebService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
public AutoComplete()
{
}

[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
DataTable dt = GetRecords(prefixText);
List<string> items = new List<string>(count);

for (int i = 0; i < dt.Rows.Count; i++)
{
string strName = dt.Rows[i][0].ToString();
items.Add(strName);
}
return items.ToArray();
}

public DataTable GetRecords(string strName)
{
string strConn = ConfigurationManager.ConnectionStrings
["DatabaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@Name", strName);
cmd.CommandText =
"Select Name from Test where Name like ''%''+@Name+''%''";
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
return objDs.Tables[0];
}
}


这篇关于具有gridview的自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆