一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ajaxControlToolkit AutoCompleteExtender的用法

AutoCompleteExtender 自動完成擴(kuò)展, 配合TextBox使用功能類似現(xiàn)在google中輸入搜索字,則在TextBox下出來下拉框顯示搜索目標(biāo)中的項(xiàng)目
這個擴(kuò)展控件需要配合Web Service使用,所以涉及了點(diǎn)web Service的使用(這里只簡單談下,等用熟了再仔細(xì)談下web service的內(nèi)容)
先介紹下AutoCompleteExtender的幾個關(guān)鍵屬性:
a,TargetControlID 這個屬性是所有AjaxControlToolkit的共同屬性,就是擴(kuò)展目標(biāo)控件ID(官方這么說的吧)
b.CompletionSetCount 這個屬性是設(shè)置顯示下拉結(jié)果的條數(shù) 默認(rèn)為10吧
c.MinimumPrefixTextLength 這個屬性是設(shè)置輸入幾個字符的長度后調(diào)用webService中的方法顯示下拉列表
d.ServicePath 這個屬性設(shè)置需要調(diào)用的web Service路徑
e.ServiceMethod 這個屬性設(shè)置需要調(diào)用的web Service中的方法(函數(shù))
f.EnableCaching:是否在客戶端緩存數(shù)據(jù),默認(rèn)為true
g.CompletionInterval:從服務(wù)器讀取數(shù)據(jù)的時間間隔,默認(rèn)為1000,單位:毫秒
注:如果習(xí)慣用可視控件設(shè)置屬性,則a屬性在AutoCompleteExtender中設(shè)置,其他屬性則設(shè)置了TargetControlId后,在相應(yīng)的TargetControl中會多出來個Extenders屬性中設(shè)置,如果習(xí)慣手寫代碼,則在AutoCompleteExtender代碼屬性中設(shè)置。
例子: 1.新建一個頁面,加入ScriptManager控件 一個TextBox控件 一個AutoCompleteExtender控件
2.新建立一個webService,添加一個[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ù)庫中的一個字段中取數(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ì)的組件,請取消注釋以下行
//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();
}
}
有哪里不對的地方還請大家指教

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

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

主站蜘蛛池模板: 国产视频福利 | 免费精品美女久久久久久久久 | 国语高清精品一区二区三区 | 韩日美女 | 国产精品极品美女自在线 | 国语自产自拍秒拍在线视频 | 夜夜穞狠狠穞 | 91在线欧美精品观看 | 欧美一级做一级做片性十三 | 国产成在线观看免费视频 | 五月婷婷深爱五月 | 四虎欧美永久在线精品免费 | 亚洲欧美国产精品 | 国产精品久久久亚洲456 | 国产精品欧美一区二区三区不卡 | 最新国产在线观看福利 | 精品免费看 | 久久国产精品久久精 | 色就色综合 | 国产一区二区高清 | 91成人免费福利网站在线 | 好吊妞在线观看 | 中文字幕一区2区3区 | 青青草一区国产97 | 国产身材极品喷水 在线播放 | 深爱五月激情 | 天天躁日日躁狠狠躁中文字幕老牛 | 全部免费69堂在线视频 | 福利视频精品 | 狠狠五月深爱婷婷网 | 青草国产在线观看 | 国产精品青青青高清在线密亚 | 黄a级网站在线观看 | 好吊色青青草 | 欧美色域| 国产熟睡乱子伦视频观看软件 | 中文字幕一区婷婷久久 | 国产永久免费高清在线观看视频 | 一区二区三区日韩精品 | 国产91对白在线播放 | 99香蕉国产精品偷在线观看 |