欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
21.9 在線(xiàn)智能輸入建議機制
21.9  在線(xiàn)智能輸入建議機制
在線(xiàn)智能輸入建議功能是目前網(wǎng)站上一個(gè)非常流行的功能。該功能能夠根據用戶(hù)輸入的部分或全部關(guān)鍵字顯示一個(gè)在線(xiàn)提示列表。因此,用戶(hù)有時(shí)不需要輸入其想要輸入的全部關(guān)鍵字,也能夠從提示框中選擇其想要輸入的信息。
實(shí)現目標
本實(shí)例介紹使用ASP.NET AJAX中的AutoCompleteExtender控件為文本輸入框添加在線(xiàn)智能輸入建議的功能。其中,該功能使用了AjaxService Web服務(wù)的GetCompleteTextList(string prefixText,int count)方法從data.txt文件中獲取在線(xiàn)建議信息。
技術(shù)實(shí)現
1.使用data.txt文件
data.txt文件放置在“Data”目錄下,它包含所有在線(xiàn)建議的提示信息。打開(kāi)該文件,如圖21-15所示。
   
(點(diǎn)擊查看大圖)圖21-15  data.txt文件
2.創(chuàng )建AjaxService Web服務(wù)
在Sample_21應用程序中創(chuàng )建AjaxService Web服務(wù),該Web服務(wù)文件的名稱(chēng)為“AjaxService.asmx”。AjaxService Web服務(wù)定義了一個(gè)名稱(chēng)為“GetCompleteTextList”的Web方法GetCompleteTextList(string prefixText,int count)。該方法從“data.txt”文件中獲取在線(xiàn)建議。具體實(shí)現步驟如下。
創(chuàng )建autoCompleteTextList變量,用來(lái)保存data.txt文件的所有數據。
判斷prefixText和count參數的值是否合法。如果不合法,則中止該方法。
如果autoCompleteTextList變量的值為空,則從“data.txt”文件中獲取數據。其中,使用按行方式讀取“data.txt”文件的數據,并保存到臨時(shí)數組tempTextList,并且對tempTextList數組進(jìn)行排序。最后將排序好的內容設置為autoCompleteTextList變量的值。
使用二叉樹(shù)搜索方法在autoCompleteTextList變量中搜索prefixText參數的值所在位置,并保存搜索的索引index。
如果在autoCompleteTextList變量中未搜索到prefixText參數的值,則把索引index設置為0。
根據索引和count參數的值從autoCompleteTextList變量中獲取在線(xiàn)建議內容,并復制到matchResultList數組中。
返回matchResultList數組的值,該數組的內容就是在線(xiàn)智能輸入建議列表中的內容。
綜上所述,創(chuàng )建AjaxService Web服務(wù)的程序代碼如下:
<%@ Page Language="C#" AutoEventWireup="true"
StylesheetTheme="Aspnet3DBWeb"
CodeFile="UpdateData.aspx.cs" Inherits="UpdateData" %>using System.IO;
[WebService(Namespace = "
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AjaxService : System.Web.Services.WebService
{
public static string[] autoCompleteTextList = null;
public AjaxService (){}
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public string[] GetCompleteTextList(string
prefixText,int count)
{   ///判斷參數是否合法
if(string.IsNullOrEmpty(prefixText) == true ||
count <= 0) return null;
if(autoCompleteTextList == null)
{   ///獲取data.txt文件的數據
StreamReader reader = new StreamReader
(Server.MapPath("Data/data.txt"));
///讀取data.txt文件的數據
ArrayList list = new ArrayList();
string rowString = reader.ReadLine();
while(rowString != null)
{   ///讀取一行數據
list.Add(rowString);
rowString = reader.ReadLine();
}
reader.Close();
string[] tempTextList = new string[list.Count];
int i = 0;
foreach(string s in list) { tempTextList[i++] = s; }
///排序數據
Array.Sort(tempTextList,new CaseInsensitiveComparer());
autoCompleteTextList = tempTextList;
}
///搜索起點(diǎn)的索引
int index = Array.BinarySearch(autoCompleteTextList,
prefixText,new CaseInsensitiveComparer());
if(index < 0){index = ~index;}   ///把起點(diǎn)設置為0
///搜索符合條件的數據
int matchCount = 0;
for(matchCount = 0; matchCount < count && matchCount
+ index < autoComplete TextList.Length;
matchCount++)
{   ///查看開(kāi)頭字符串相同的項
if(autoCompleteTextList[index + matchCount].
StartsWith(prefixText,
StringComparison.CurrentCultureIgnoreCase)
== false){ break; }
}
string[] matchResultList = new string[matchCount];
if(matchCount > 0)
{   ///復制搜索結果
Array.Copy(autoCompleteTextList,index,
matchResultList,0,matchCount);
}
return matchResultList;
}
}
3.創(chuàng )建AjaxSuggest.aspx頁(yè)面
在Sample_21應用程序中創(chuàng )建AjaxSuggest.aspx頁(yè)面,并在該頁(yè)面上創(chuàng )建一個(gè)ScriptManager控件、一個(gè)UpdatePanel控件、一個(gè)TextBox控件和一個(gè)AutoCompleteExtender控件。這些控件的ID屬性的值分別為sm、up、tbValue和aceValue。其中,sm和up控件共同提供無(wú)刷新的Web環(huán)境。tbValue控件供用戶(hù)輸入值。aceValue控件為tbValue控件實(shí)現在線(xiàn)智能輸入建議功能。
★ 注意 ★
aceValue控件使用AjaxService.asmx Web服務(wù)。并使用該Web服務(wù)中的GetCompleteTextList(string prefixText, int count)方法獲取在線(xiàn)建議數據。
AjaxSuggest.aspx頁(yè)面的部分HTML設計代碼如下:
<%@ Page Language="C#" AutoEventWireup="true"
StylesheetTheme="Aspnet3DBWeb"
CodeFile="LinqProcedure.aspx.cs" Inherits="LinqProcedure" %>
把AjaxSuggest.aspx頁(yè)面設置為Sample_21應用程序的起始頁(yè)面,并運行該應用程序。在輸入框中輸入“D”,此時(shí),AjaxSuggest.aspx頁(yè)面在輸入框下方顯示一個(gè)在線(xiàn)建議提示面板,如圖21-16所示。
   
圖21-16  AjaxSuggest.aspx頁(yè)面顯示在線(xiàn)建議提示面板
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
.Net 2.0 正則表達式里的$在Multiline模式下的精確含意
使用AutoCompleteExtender實(shí)現文本框自動(dòng)匹配
C# WinForm TextBox猜想輸入和歷史記錄輸入(源碼)
textbox錄入標題時(shí)實(shí)檢測相同數據
Effective STL
ASP.net指定框架顯示
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久