本文仍然是学习总结,说明这里的来源浪曦下载视频教程 主要实现功能类似google下拉,输入字符随机提供10条供选择,扩展应用把WebService数据操作改成从数据读取等,前台通过拖放控件和设置后代码如下 - <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
-
- <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>AJAX控件之AutoComplete</title>
- </head>
- <body style="text-align: center">
- <form id="form1" runat="server">
- <asp:ScriptManager ID="ScriptManager1" runat="server" />
- <div>
- <asp:TextBox ID="MyAuto" runat="server" Width="191px"></asp:TextBox><br />
- <br />
- <cc1:AutoCompleteExtender ID="ace" runat="server" CompletionInterval="100" MinimumPrefixLength="1"
- ServiceMethod="GetCompletionList" ServicePath="WebService.asmx" TargetControlID="MyAuto">
- </cc1:AutoCompleteExtender>
- </div>
- </form>
- </body>
- </html>
-
WebService代码如下,注意写 [System.Web.Script.Services.ScriptService] //用以调用Web Service方法签名 - using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Web.Services;
- using System.Web.Services.Protocols;
-
-
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.Web.Script.Services.ScriptService]
- public class WebService : System.Web.Services.WebService {
-
- public WebService () {}
-
- [WebMethod]
- public string[] GetCompletionList(string prefixText, int count)
- {
-
-
-
-
- Random random = new Random();
- List<string> items = new List<string>(count);
- for (int i = 0; i < count; i++)
- {
- char c1 = (char)random.Next(65,90);
- char c2 = (char)random.Next(97, 122);
- char c3 = (char)random.Next(48, 57);
- char c4 = (char)random.Next(33, 43);
- items.Add(prefixText + c1 + c2 + c3 + c4);
- }
- return items.ToArray();
- }
-
- }
-
-
(责任编辑:admin) |