实现textbox输入时模糊查询
2010-05-06 14:50
447 查看
时间有点紧,有点浮躁,暂时只把相关的文件挑出来看下,思路有时间再整理
1。引用的一个文件
代码
public partial class AutoComplete : System.Web.UI.Page
{
CommBO bo = new CommBO();
string flag = string.Empty;// 标示符
string InputValue = string.Empty;//输入值
string ReturnStr = string.Empty;//xml
// 页面加载事件
protected void Page_Load(object sender, EventArgs e)
{
try
{
flag = Request.QueryString["flag"] ?? "";//查询条件标示符
InputValue = Request.QueryString["InputValue"];//输入值
AutoCompletXML();//填充xml
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);//禁用本地缓存
HttpContext.Current.Response.Cache.SetNoStore();
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
HttpContext.Current.Response.Write( ReturnStr);
HttpContext.Current.Response.End();
}
catch
{ ; }
}
// 填充xml
private void AutoCompletXML()
{
try
{
Dictionary<string, object> dict = new Dictionary<string, object>();
DataSet ds = new DataSet();
int intRowCount = 10;//默认自动完成显示最大行数
intRowCount = Convert.ToInt32(ConfigurationManager.AppSettings["AutoCompleteRowCount"].Trim());
if (flag.Equals("1"))
{
dict.Add("@" + ConstMessage.TABLE_FIELD_NAME.Product.PRODUCTCODE ,"%" + InputValue +"%");
}
else if (flag.Equals("2"))
{
dict.Add("@" + ConstMessage.TABLE_FIELD_NAME.Product.PRODUCTNAME ,"%"+ InputValue +"%");
}
else
{
return;
}
//执行数据库操作
ds = bo.GetByProduct(dict,intRowCount);
ReturnStr = ds.GetXml();//生成xml
}
catch
{
ReturnStr = string.Empty;
}
}
}
3。使用页面,对应的页面控件
----添加js引用
----页面添加控件
<div>
<asp:TextBox ID="txtProductCode" runat="server" CssClass="text_Mandatory" MaxLength="25"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:TextBox ID="txtProductName" runat="server" CssClass="text_ProductName" MaxLength="30"
AutoCompleteType="Disabled"></asp:TextBox>
</div>
---cs中为txtbox添加js事件
this.txtProductCode.Attributes.Add("onkeyup", "findNames('" + this.txtProductCode.ClientID + "','" + this.txtProductName.ClientID + "','1');");
this.txtProductName.Attributes.Add("onkeyup", "findNames('" + this.txtProductName.ClientID + "','" + this.txtProductCode.ClientID + "','2');");
this.txtProductCode.Attributes.Add("onblur", "lostfocus(this);");
this.txtProductName.Attributes.Add("onblur", "lostfocus(this);");
4。数据库调用层根据编码或名称的模糊查询略
1。引用的一个文件
代码
public partial class AutoComplete : System.Web.UI.Page
{
CommBO bo = new CommBO();
string flag = string.Empty;// 标示符
string InputValue = string.Empty;//输入值
string ReturnStr = string.Empty;//xml
// 页面加载事件
protected void Page_Load(object sender, EventArgs e)
{
try
{
flag = Request.QueryString["flag"] ?? "";//查询条件标示符
InputValue = Request.QueryString["InputValue"];//输入值
AutoCompletXML();//填充xml
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);//禁用本地缓存
HttpContext.Current.Response.Cache.SetNoStore();
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
HttpContext.Current.Response.Write( ReturnStr);
HttpContext.Current.Response.End();
}
catch
{ ; }
}
// 填充xml
private void AutoCompletXML()
{
try
{
Dictionary<string, object> dict = new Dictionary<string, object>();
DataSet ds = new DataSet();
int intRowCount = 10;//默认自动完成显示最大行数
intRowCount = Convert.ToInt32(ConfigurationManager.AppSettings["AutoCompleteRowCount"].Trim());
if (flag.Equals("1"))
{
dict.Add("@" + ConstMessage.TABLE_FIELD_NAME.Product.PRODUCTCODE ,"%" + InputValue +"%");
}
else if (flag.Equals("2"))
{
dict.Add("@" + ConstMessage.TABLE_FIELD_NAME.Product.PRODUCTNAME ,"%"+ InputValue +"%");
}
else
{
return;
}
//执行数据库操作
ds = bo.GetByProduct(dict,intRowCount);
ReturnStr = ds.GetXml();//生成xml
}
catch
{
ReturnStr = string.Empty;
}
}
}
3。使用页面,对应的页面控件
----添加js引用
----页面添加控件
<div>
<asp:TextBox ID="txtProductCode" runat="server" CssClass="text_Mandatory" MaxLength="25"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:TextBox ID="txtProductName" runat="server" CssClass="text_ProductName" MaxLength="30"
AutoCompleteType="Disabled"></asp:TextBox>
</div>
---cs中为txtbox添加js事件
this.txtProductCode.Attributes.Add("onkeyup", "findNames('" + this.txtProductCode.ClientID + "','" + this.txtProductName.ClientID + "','1');");
this.txtProductName.Attributes.Add("onkeyup", "findNames('" + this.txtProductName.ClientID + "','" + this.txtProductCode.ClientID + "','2');");
this.txtProductCode.Attributes.Add("onblur", "lostfocus(this);");
this.txtProductName.Attributes.Add("onblur", "lostfocus(this);");
4。数据库调用层根据编码或名称的模糊查询略
相关文章推荐
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- [导入]Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中(ZT)
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- ajaxpro实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- 实现textbox输入时模糊查询
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Ajax实现在textbox中输入内容,动态从数据库中模糊查询显示到下拉框中
- Combobox通过输入框所输入内容的改变实现模糊查询
- asp中在一个页面输入查询条件,另一个页面的textbox中实现显示,修改和删除
- 章鱼哥出品_VB.NET ComboBox、 TextBox 实现自动完成、自动过滤 模糊查询的功能
- VB6对系统自带的TextBox控件的扩展实现模糊查询的功能
- 求助!!EXCEL里如何实现模糊查询的输入方式。