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

ajaxControlToolkit AutoCompleteExtender的用法

AutoCompleteExtender 自動完成擴展, 配合TextBox使用功能類似現(xiàn)在google中輸入搜索字,則在TextBox下出來下拉框顯示搜索目標中的項目
這個擴展控件需要配合Web Service使用,所以涉及了點web Service的使用(這里只簡單談下,等用熟了再仔細談下web service的內容)
先介紹下AutoCompleteExtender的幾個關鍵屬性:
a,TargetControlID 這個屬性是所有AjaxControlToolkit的共同屬性,就是擴展目標控件ID(官方這么說的吧)
b.CompletionSetCount 這個屬性是設置顯示下拉結果的條數(shù) 默認為10吧
c.MinimumPrefixTextLength 這個屬性是設置輸入幾個字符的長度后調用webService中的方法顯示下拉列表
d.ServicePath 這個屬性設置需要調用的web Service路徑
e.ServiceMethod 這個屬性設置需要調用的web Service中的方法(函數(shù))
f.EnableCaching:是否在客戶端緩存數(shù)據(jù),默認為true
g.CompletionInterval:從服務器讀取數(shù)據(jù)的時間間隔,默認為1000,單位:毫秒
注:如果習慣用可視控件設置屬性,則a屬性在AutoCompleteExtender中設置,其他屬性則設置了TargetControlId后,在相應的TargetControl中會多出來個Extenders屬性中設置,如果習慣手寫代碼,則在AutoCompleteExtender代碼屬性中設置。
例子: 1.新建一個頁面,加入ScriptManager控件 一個TextBox控件 一個AutoCompleteExtender控件
2.新建立一個webService,添加一個[WebMethod]方法
[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類是項目中的取數(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ù)
頁面代碼: 
復制代碼 代碼如下:
<%@ 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簡單練習</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)]
//下面是必須的,否則功能無法實現(xiàn)
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//如果使用設計的組件,請取消注釋以下行
//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類是項目中的取數(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技術ajaxControlToolkit AutoCompleteExtender的用法,轉載需保留來源!

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

主站蜘蛛池模板: 久久久高清国产999尤物 | 亚洲男人天堂2018av | 高h np 强j 乱l 双性 | 又紧又大又爽精品一区二区 | 久久无码人妻中文国产 | 乱精品一区字幕二区 | 久久中文电影 | 偷偷鲁青春草原视频分类 | 亚洲国产成人久久一区www妖精 | 影音先锋色av男人资源网 | 伊人影院久久 | 久草大 | 久久毛片视频 | 午夜天堂一区人妻 | 人妖xxhdxx | 精彩国产萝视频在线 | 国产成人99久久亚洲综合精品 | 精品国产乱码久久久久久免费流畅 | www国产av偷拍在线播放 | 亚洲精品无码久久久久A片空 | 国产精品爆乳尤物99精品 | 久久国产精品永久网站 | 丰满女友bd高清在线观看 | WWW国产精品人妻一二三区 | 1788vv视频 | 2022国产麻豆剧传媒剧情 | 国产亚洲精品久久久无码狼牙套 | 色欲国产麻豆一精品一AV一免费 | 青草精品国产福利在线视频 | 在线视频a| 人妖xxhdxx| 久久性色AV亚洲电影无码 | 亚洲精品在线观看视频 | 国产午夜不卡 | 亚洲AV久久无码精品九号软件 | 欧美兽交YOYO | 大陆老太交xxxxxhd在线 | 60岁老年熟妇在线无码 | 97久久精品人人槡人妻人 | 小莹的性荡生活 | 精品亚洲AV无码蜜芽麻豆 |