• 使用AutoCompleteExtender在服务器端获取提示数据提示客户选择


    上个星期做的小demo使得可以像百度一样的智能提示信息(信息从数据库中检索)

    过程:

    1、新建一个空网站,添加一个程序运行的主界面和一个WebService的web服务页面
    2、在主界面拖拉一个ScriptManager、TextBox 、AutoCompleteExtender 
    3、在WebService中写调用的方法,
    4、首先判断有没有传值到这个方法,连接数据库
    5、将数据库中的数据按着传过来的值模糊查询并将结果填充到数据集ds中
    6、声明一个数组,并且将数组的长度设置为数据集中可以读取到的行数
    7、将数据集中药返回的行数读取到声明的数组中去
    8、返回数组

    最重要的webservers的代码:

    View Code
     1  public string[] getWord(string prefixText, int count)
     2      {
     3          if (string.IsNullOrEmpty(prefixText) == true || count <= 0)
     4              return null;
     5          else
     6          {
     7              string sql = "server=.;database=stu;Integrated Security=True";
     8              SqlConnection conn = new SqlConnection(sql);
     9              string strsql = "select sname from st where sname like'" + 
    10 
    11 prefixText + "%'";
    12              SqlDataAdapter da = new SqlDataAdapter(strsql, conn);
    13              DataSet ds = new DataSet();
    14              da.Fill(ds, "stu");
    15              string[] returnvalue = new string[ds.Tables["stu"].Rows.Count];
    16              for (int i = 1; i <= ds.Tables["stu"].Rows.Count; i++)
    17              {
    18                  returnvalue[i - 1] = ds.Tables["stu"].Rows[i - 1][0].ToString
    19 
    20 ();
    21              }
    22              return returnvalue;
    23          }
    24      }

    需要注意的是我是在VS10中写的,不知道为什么参数名字只能是prefixText

    接下来只需要在将AutoCompleteExtender的ServiceMethod改为"getWord"就可以实现了

    如果没有看懂的同学,在此提供我的源码http://download.csdn.net/detail/qinpei11/4783973

  • 相关阅读:
    寒假作业4
    UVA5870 乱搞 Smooth Visualization
    UVA5874 Social Holidaying 二分匹配
    UVA5876 Writings on the Wall 扩展KMP
    hdu1231 最大连续子序列
    hdu3535 混合背包
    hdu3613 扩展KMP
    hdu4333 扩展KMP
    扩展KMP
    hdu4287 字典树
  • 原文地址:https://www.cnblogs.com/netqin/p/2777467.html
Copyright © 2020-2023  润新知