TextBox输入值自动获取后台匹配值

31 篇文章 0 订阅
7 篇文章 0 订阅

AjaxPro.NET实现TextBox智能获取服务端数据功能
AjaxPro.NET是一个优秀的Ajax框架, 在实际应用中只要添加其DLL引用并进行简单的配置,
即可以非常方便的在客户端直接调用服务端方法, 实现验证目的.

效果图显示:

前台调用代码:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="AutoQueryTextBox.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
    <title>AutoQueryTextBox</title>
    <script language="javascript" src="lookup.js"></script>
	<script language="jscript">
		mainLoop = function () {
		    val = escape(queryField.value);
		    if (lastVal != val) {
		        var response = _Default.GetSearchItems(val);
		        showQueryDiv(response.value);
		        lastVal = val;
		    }
		    setTimeout('mainLoop()', 100);
		    return true;
		}        
    </script>
</head>
<body >
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server" BackColor="#C0C0FF" Font-Bold="True" Font-Overline="False" Font-Size="XX-Large" Height="37px" Width="475px">AutoQueryTextBox</asp:Panel>
        <br />
        <hr align="left" style="width: 473px" />
        <br />
        输入查询字串:   <asp:TextBox ID="txSearch" runat="server" Width="134px"></asp:TextBox> <br />
        <br />
    </div>
    <script language="jscript">
        InitQueryCode("" + '<%= txSearch.ClientID %>' + "");
    </script>    
    </form>
</body>
</html>


后台方法调用:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using AjaxPro;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {       
       Utility.RegisterTypeForAjax(typeof(_Default));
    }

   [AjaxMethod()]// or [AjaxPro.AjaxMethod] 
   public ArrayList GetSearchItems( string strQuery )
   {
      //生成数据源
      ArrayList items = new ArrayList();
      items.Add("Codefans.net");
      items.Add("code");
      items.Add("cso");
	  items.Add("abcdefg");
	  items.Add("cso");
	  items.Add("ajax");
	  items.Add("236");
	  items.Add("qzone");
      items.Add("123");
      items.Add("5678.com");
      items.Add("www.baidu.com");
      items.Add("aspx.net"); 

      //筛选数据
      ArrayList selectItems = new ArrayList();
      foreach( string str in items )
      {
         if (str.ToUpper().IndexOf(strQuery.ToUpper()) == 0)
         {
            selectItems.Add(str);
         }
      }
      return selectItems;
   }  
}

 

来源于:http://www.codefans.net
案例下载地址1:http://download.csdn.net/detail/lovegonghui/9177325

案例下载地址2:http://down.51cto.com/data/2105139

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值