您的位置:首页 > 其它

Atlas 学习笔记: ajax 改进 by Atlas

2006-03-16 13:26 323 查看
废话不多说,今天试试atlas

1. 加入atlas 的 scriptManager 因为是后台直接调webservice 所以加上webservice的地址

<atlas:ScriptManager ID="scriptManager" runat="server">
<Services>
<atlas:ServiceReference Path="WebService.asmx" />
</Services>
</atlas:ScriptManager>

2. OK 在来一个text 注意在后面 spanid 要加一个名字 这个名字要和下面对应起来
<input id="Text1" type="text" /><span id="Text1__autocomplete"></span>

3. 这段代码大家看看 指定 text1 要完成的行为 behaviors 里面指定了autoComplete 指定了方法serviceMethod="GetCompletionList" minimumPrefixLength ="1" 指定你输入多少个字符就开始触发这个auto事件最后 completionList ="Text1__autocomplete" 这个名字和第二步的名字 要统一

</script>

4 下面来写webservice时候实现 的代码 基本上就是一个查询 注意返回值的类型

[WebMethod]
public string[] GetCompletionList(string prefixText)
string temp = "";
List<string> suggestions = new List<string>();
if (prefixText != "")
string mySelectQuery = "SELECT ContactName FROM Customers where ContactName like '" + prefixText + "%'";
SqlConnection myConnection = new SqlConnection(@"server=ZTE-WUANCHENG\wuancheng_zte;database=Northwind;User ID=sa;password=;Persist Security Info=true;");
SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();

try
while (myReader.Read())
suggestions.Add(myReader.GetString(0));
temp = temp + myReader.GetString(0) + ", ";
}

}
finally
// always call Close when done reading.
myReader.Close();
// always call Close when done reading.
myConnection.Close();
}
}

return suggestions.ToArray();
}

5 . ok 看看效果



还可以把 参考了altas 的例子
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: