天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

ajaxControlToolkit AutoCompleteExtender的用法

AutoCompleteExtender 自動(dòng)完成擴(kuò)展, 配合TextBox使用功能類似現(xiàn)在google中輸入搜索字,則在TextBox下出來下拉框顯示搜索目標(biāo)中的項(xiàng)目
這個(gè)擴(kuò)展控件需要配合Web Service使用,所以涉及了點(diǎn)web Service的使用(這里只簡單談下,等用熟了再仔細(xì)談下web service的內(nèi)容)
先介紹下AutoCompleteExtender的幾個(gè)關(guān)鍵屬性:
a,TargetControlID 這個(gè)屬性是所有AjaxControlToolkit的共同屬性,就是擴(kuò)展目標(biāo)控件ID(官方這么說的吧)
b.CompletionSetCount 這個(gè)屬性是設(shè)置顯示下拉結(jié)果的條數(shù) 默認(rèn)為10吧
c.MinimumPrefixTextLength 這個(gè)屬性是設(shè)置輸入幾個(gè)字符的長度后調(diào)用webService中的方法顯示下拉列表
d.ServicePath 這個(gè)屬性設(shè)置需要調(diào)用的web Service路徑
e.ServiceMethod 這個(gè)屬性設(shè)置需要調(diào)用的web Service中的方法(函數(shù))
f.EnableCaching:是否在客戶端緩存數(shù)據(jù),默認(rèn)為true
g.CompletionInterval:從服務(wù)器讀取數(shù)據(jù)的時(shí)間間隔,默認(rèn)為1000,單位:毫秒
注:如果習(xí)慣用可視控件設(shè)置屬性,則a屬性在AutoCompleteExtender中設(shè)置,其他屬性則設(shè)置了TargetControlId后,在相應(yīng)的TargetControl中會(huì)多出來個(gè)Extenders屬性中設(shè)置,如果習(xí)慣手寫代碼,則在AutoCompleteExtender代碼屬性中設(shè)置。
例子: 1.新建一個(gè)頁面,加入ScriptManager控件 一個(gè)TextBox控件 一個(gè)AutoCompleteExtender控件
2.新建立一個(gè)webService,添加一個(gè)[WebMethod]方法
[WebMethod] 
復(fù)制代碼 代碼如下:
public string[] GetString(string prefixText, int count){
System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(count);
System.Data.DataSet ds = new System.Data.DataSet();
//這里是我在數(shù)據(jù)庫中取數(shù)據(jù)的代碼 其中SqlHelper類是項(xiàng)目中的取數(shù)據(jù)基類
//string strSql = string.Format("SELECT TOP {0} NAME FROM CengWei WHERE NAME LIKE '{1}%' ORDER BY NAME",count,prefixText);
//ds = SqlHelper.Query(strSql);
//for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
//{
// list.Add(ds.Tables[0].Rows[i][0].ToString());
//}
for (int i = 0; i < count; i++)
{
list.Add(prefixText+i.ToString());
}
return list.ToArray();
}

其中:必須在webService的類上面添加
[System.Web.Script.Services.ScriptService]
示例代碼:webService是在數(shù)據(jù)庫中的一個(gè)字段中取數(shù)據(jù)
頁面代碼: 
復(fù)制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.ASPx.cs" Inherits="test2" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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>DropDownExtender簡單練習(xí)</title>
<link href="/ASPNET_client/System_Web/2_0_50727/CrystalReportWebFormViewer3/css/default.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<ASP:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="True" EnableScriptLocalization="True">
</ASP:ScriptManager>
<ASP:TextBox ID="TextBox3" runat="server"></ASP:TextBox>
<ASP:TextBox ID="TextBox4" runat="server"></ASP:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" MinimumPrefixLength="1"
ServiceMethod="GetString" ServicePath="AutoComplete.asmx" TargetControlID="TextBox2">
</cc1:AutoCompleteExtender>
</form>
</body>
</html>

webService代碼:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <summary>
/// AutoComplete 的摘要說明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//下面是必須的,否則功能無法實(shí)現(xiàn)
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//如果使用設(shè)計(jì)的組件,請(qǐng)取消注釋以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string[] GetString(string prefixText, int count){
System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(count);
System.Data.DataSet ds = new System.Data.DataSet();
//這里是我在數(shù)據(jù)庫中取數(shù)據(jù)的代碼 其中SqlHelper類是項(xiàng)目中的取數(shù)據(jù)基類
//string strSql = string.Format("SELECT TOP {0} NAME FROM CengWei WHERE NAME LIKE '{1}%' ORDER BY NAME",count,prefixText);
//ds = SqlHelper.Query(strSql);
//for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
//{
// list.Add(ds.Tables[0].Rows[i][0].ToString());
//}
for (int i = 0; i < count; i++)
{
list.Add(prefixText+i.ToString());
}
return list.ToArray();
}
}
有哪里不對(duì)的地方還請(qǐng)大家指教

JavaScript技術(shù)ajaxControlToolkit AutoCompleteExtender的用法,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产在线精品亚洲观看不卡欧美 | 亚洲欧美中文字幕网站大全 | 久久青草影院 | 亚洲国产综合久久精品 | 蜜柚在线观看免费高清官网视频 | 亚洲妈妈精品一区二区三区 | 米奇影视999 | 少妇的肉体AA片免费观看 | 午夜成a人片在线观看 | 超碰在线视频地址 | 波多野结衣的AV一区二区三区 | 粉嫩无套白浆第一次jk | 91嫩草私人成人亚洲影院 | 嗯啊哈啊好棒用力插啊 | 伊人情人网综合 | 99爱在线观看精品视频 | 动漫美女被到爽了流漫画 | 久久精品中文字幕有码日本 | 好大快用力深一点h视频 | 永久免费在线看mv | 亚洲中文久久精品AV无码 | 久久精品一卡二卡三卡四卡视频版 | 十九岁韩国电影在线观看 | 大胸美女被c | 亚洲 无码 在线 专区 | 久久久久国产精品美女毛片 | 草神被爆漫画羞羞漫画 | 人人草人人草 | 国产亚洲精品久久久999密臂 | 强奷表妺好紧2 | 久久国产精品免费A片蜜芽 久久国产精品萌白酱免费 久久国产精品麻豆AV影视 | 成人在线免费视频播放 | 亚洲精品AV中文字幕在线 | 色欲久久精品AV无码 | 欧洲精品一区二区不卡观看 | 日本精品久久无码影院 | 一本一本之道高清在线观看 | 99精产国品一二产区在线 | 伊人久久电影院 | 九九精品视频一区二区三区 | 日韩欧美中文字幕一区 |